Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:1.8
WORKDIR /go/src/app
COPY GeoIP2-Country.mmdb /go/src/app
COPY GeoLite2-City.mmdb /go/src/app
COPY ip2country.go /go/src/app

RUN go get -d -v github.com/oschwald/geoip2-golang
Expand Down
13 changes: 13 additions & 0 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.4"

services:
ip2country:
image: "nexus-ng.themarker.com/ip2country:${version:-latest}"
hostname: ip2counrty
networks:
- production
ports:
- "4005:8080"
networks:
production:
external: true
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3.4"
services:
ip2country:
build: .
deploy:
mode: replicated
replicas: 1
image: "nexus-ng.themarker.com/ip2country:${version:-latest}"
ports:
- "4005:4005"
4 changes: 3 additions & 1 deletion ip2country.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
geoip2 "github.com/oschwald/geoip2-golang"
)

var dbFile = "GeoIP2-Country.mmdb"
var dbFile = "GeoLite2-City.mmdb"

func handler(w http.ResponseWriter, r *http.Request) {
db, err := geoip2.Open(dbFile)
Expand All @@ -39,6 +39,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
resp := make(map[string]string, 2)
resp["country"] = record.Country.Names["en"]
resp["code"] = record.Country.IsoCode
resp["city"] = record.City.Names["en"]
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(resp)
}
Expand All @@ -57,3 +58,4 @@ func errorHandler(w http.ResponseWriter, r *http.Request, status int, msg string
fmt.Fprint(w, msg)
}
}