ソースを参照

Merge pull request #4 from kodnaplakal/feature/fix_concurent_map_writes

Fix fatal error: concurrent map writes #3 Issue
Andrey Blinov 6 年 前
コミット
d8c2ba1daf
2 ファイル変更5 行追加3 行削除
  1. 1 0
      .gitignore
  2. 4 3
      setup.go

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 db/
+.idea

+ 4 - 3
setup.go

@@ -10,8 +10,8 @@ import (
 
 	"github.com/mholt/caddy"
 	"github.com/mholt/caddy/caddyhttp/httpserver"
-	maxminddb "github.com/oschwald/maxminddb-golang"
-)
+	"github.com/oschwald/maxminddb-golang"
+	)
 
 // GeoIP represents a middleware instance
 type GeoIP struct {
@@ -20,7 +20,7 @@ type GeoIP struct {
 	Config    Config
 }
 
-var record struct {
+type GeoIPRecord struct {
 	Country struct {
 		ISOCode           string            `maxminddb:"iso_code"`
 		IsInEuropeanUnion bool              `maxminddb:"is_in_european_union"`
@@ -80,6 +80,7 @@ func (gip GeoIP) lookupLocation(w http.ResponseWriter, r *http.Request) {
 	clientIP, _ := getClientIP(r, true)
 	replacer := newReplacer(r)
 
+	var record = GeoIPRecord{}
 	err := gip.DBHandler.Lookup(clientIP, &record)
 	if err != nil {
 		log.Println(err)