ip2region.go 437 B

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