ip2region.go 421 B

123456789101112131415161718192021222324
  1. package ip2region
  2. import (
  3. "fmt"
  4. "github.com/lionsoul2014/ip2region/binding/golang/ip2region"
  5. )
  6. func Ip2Region(ip string) (*ip2region.IpInfo, error) {
  7. region, err := ip2region.New("./conf/ip2region_20200113.db")
  8. if region != nil {
  9. defer region.Close()
  10. }
  11. if err != nil {
  12. fmt.Println(err)
  13. return nil, err
  14. }
  15. ipInfo, err := region.BtreeSearch(ip)
  16. if err != nil {
  17. return nil, err
  18. }
  19. return &ipInfo, nil
  20. }