mirror of
https://github.com/warmbly/warmbly.git
synced 2026-08-19 08:01:16 +00:00
28 lines
365 B
Go
28 lines
365 B
Go
package geo
|
|
|
|
import "github.com/oschwald/geoip2-golang/v2"
|
|
|
|
type Client struct {
|
|
r *geoip2.Reader
|
|
}
|
|
|
|
func New(location string) (*Client, error) {
|
|
if location == "" {
|
|
return &Client{
|
|
r: nil,
|
|
}, nil
|
|
}
|
|
db, err := geoip2.Open(location)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Client{
|
|
r: db,
|
|
}, nil
|
|
}
|
|
|
|
func (c *Client) Close() {
|
|
_ = c.r.Close()
|
|
}
|