Andrey Blinov 7 年 前
コミット
4d2a592081
3 ファイル変更55 行追加1 行削除
  1. 8 0
      .travis.yml
  2. 46 0
      README.md
  3. 1 1
      handler_test.go

+ 8 - 0
.travis.yml

@@ -0,0 +1,8 @@
+language: go
+go:
+- 1.9
+
+before_script:
+- go get -u github.com/mholt/caddy
+
+script: go test .

+ 46 - 0
README.md

@@ -0,0 +1,46 @@
+## Overview
+
+`geoip` is a Caddy plugin that allow to determine user Geolocation by IP address using MaxMind database.
+
+## Headers
+
+`geoip` set this headers:
+
+```
+  X-Geoip-Country-Code - Country ISO code, example CY for Cyprus
+  X-Geoip-Location-Lat - Latitude, example 34.684100
+  X-Geoip-Location-Lon - Longitude, example 33.037900
+  X-Geoip-Location-Tz - Time zone, example Asia/Nicosia
+  X-Geoip-Country-Eu - Return `true` if country in Europen Union
+  X-Geoip-Country-Name - Full country name
+  X-Geoip-City-Name - City name
+```
+
+
+## Examples
+
+(1) Set database path:
+
+```
+geoip {
+  database /path/to/db/GeoLite2-City.mmdb
+}
+```
+
+
+(2) Set custom header names.
+
+```
+geoip {
+  database path/to/maxmind/db
+  set_header_country_code Code
+  set_header_country_name CountryName
+  set_header_country_eu Eu
+  set_header_city_name CityName
+  set_header_location_lat Lat
+  set_header_location_lon Lon
+  set_header_location_tz TZ
+}
+```
+
+    

+ 1 - 1
handler_test.go

@@ -32,7 +32,7 @@ func TestToResolveGeoip(t *testing.T) {
 	var (
 		gotHeaders      http.Header
 		expectedHeaders = http.Header{
-			"X-Geoip-Country-Code": []string{"CY"},
+			"X-Geoip-Country-Code": []string{"C1Y"},
 			"X-Geoip-Location-Lat": []string{"34.684100"},
 			"X-Geoip-Location-Lon": []string{"33.037900"},
 			"X-Geoip-Location-Tz":  []string{"Asia/Nicosia"},