Skip to content

Commit

Permalink
template rename
Browse files Browse the repository at this point in the history
  • Loading branch information
thc committed Apr 30, 2021
1 parent 5d67941 commit 5028ab1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion get_extract_give_name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ tar zxf GeoLite2-Country.tar.gz

GEOIPDATANAME=`ls GeoLite2-Country_*/GeoLite2-Country.mmdb`

sed "s+%%GEOIPDATANAME%%+$GEOIPDATANAME+g" < template/init.go > init.go
sed "s+%%GEOIPDATANAME%%+$GEOIPDATANAME+g" < template/init_go.tpl > init.go
30 changes: 30 additions & 0 deletions template/init_go.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import (
_ "embed"
"log"

geoip2 "github.com/oschwald/geoip2-golang"
)

//go:embed %%GEOIPDATANAME%%
var embeddeddata []byte

func initdb() *geoip2.Reader {
// data, err := Asset(Assetname)
// if err != nil {
// // Asset was not found.
// log.Fatal("Error opening Asset ", Assetname)
// }
// // Memo : Instead of opening the file, embedding it with
// // db, err := geoip2.Open("/local/etc/GeoLite2-Country.mmdb")

db, err := geoip2.FromBytes(embeddeddata)
if err != nil {
log.Fatal(err)
}
return db
}

var Assetname = "%%GEOIPDATANAME%%"

0 comments on commit 5028ab1

Please sign in to comment.