ip2region.go 402 B

12345678910111213141516171819202122
  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. fmt.Println("err")
  8. region, err := ip2region.New("./ip2region.db")
  9. defer region.Close()
  10. if err != nil {
  11. fmt.Println(err)
  12. return nil, err
  13. }
  14. ipInfo, err := region.BtreeSearch(ip)
  15. if err != nil {
  16. return nil, err
  17. }
  18. return &ipInfo, nil
  19. }