Go 1.8 gives us a new tool for creating shared libraries, called plugins! This new plugin buildmode is currently only supported on Linux. But what if we build plugin with data in binary format inside? So we can ship only one
I tried with go-bindata tool.
Plugin to find a city by http.Request
It’s for experimental usage only!
It can find City by IP address.
It builds single
go-maxmind-geoip.so plugin file with already included database with help of
go get github.com/oschwald/geoip2-golang go get github.com/jteeuwen/go-bindata/... go-bindata -o geoip2-city.go geoip2-city.mmdb go build -buildmode=plugin -o go-maxmind-geoip.so go-maxmind-geoip.go geoip2-city.go
How to use in Go
p, _ := plugin.Open("./go-maxmind-geoip.so") init, _ := p.Lookup("InitDB") init.(func() error)() gc, _ := p.Lookup("GetCity") city, _ := gc.(func(r *http.Request) (string, error))(r)
It will probably be a while before plugins see much adoption and I currently would not recommend using them in any large project.