utils

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GeoDB = "GeoLite2-City.mmdb"
)

Functions

func Compress

func Compress(p []byte) ([]byte, error)

func Decompress

func Decompress(p []byte) ([]byte, error)

func Format

func Format(in, out interface{}) error

in format out eg: Format(map[string]interface{...}, &Struct{})

func Int

func Int(v interface{}) int

Types

type City

type City struct {
	GeonameId ID    `json:"geoname_id"`
	Names     Names `json:"names"`
}

type Client

type Client struct {
	*maxminddb.Reader
}
var GeoIPClient *Client

func NewClient

func NewClient(db string) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Search

func (c *Client) Search(ip string) (*GeoIP, error)

type Continent

type Continent struct {
	GeonameId ID     `json:"geoname_id"`
	Names     Names  `json:"names"`
	Code      string `json:"code"`
}

type Country

type Country struct {
	GeonameId ID     `json:"geoname_id"`
	Names     Names  `json:"names"`
	IsoCode   string `json:"iso_code"`
}

type EsIP

type EsIP struct {
	Timezone      string  `json:"timezone,omitempty"`
	Ip            string  `json:"ip,omitempty"`
	Latitude      float64 `json:"latitude,omitempty"`
	ContinentCode string  `json:"continent_code,omitempty"`
	CityName      string  `json:"city_name,omitempty"`
	CountryName   string  `json:"country_name,omitempty"`
	CountryCode2  string  `json:"country_code2,omitempty"`
	DmaCode       int     `json:"dma_code,omitempty"`
	CountryCode3  string  `json:"country_code3,omitempty"`
	RegionName    string  `json:"region_name,omitempty"`
	Location      struct {
		Lon float64 `json:"lon,omitempty"`
		Lat float64 `json:"lat,omitempty"`
	} `json:"location,omitempty"`
	PostalCode string  `json:"postal_code,omitempty"`
	RegionCode string  `json:"region_code,omitempty"`
	Longitude  float64 `json:"longitude,omitempty"`
}

func GeoToEsIP

func GeoToEsIP(geoip *GeoIP) *EsIP

type GeoIP

type GeoIP struct {
	IP                string            `json:"ip"`
	City              City              `json:"city"`
	Continent         Continent         `json:"continent"`
	Country           Country           `json:"country"`
	Location          Location          `json:"location"`
	Postal            Postal            `json:"postal"`
	RegisteredCountry RegisteredCountry `json:"registered_country"`
	Subdivisions      []Subdivision     `json:"subdivisions"`
}

type ID

type ID = uint64

type Location

type Location struct {
	Longitude      float64 `json:"longitude"`
	TimeZone       string  `json:"time_zone"`
	AccuracyRadius int     `json:"accuracy_radius"`
	Latitude       float64 `json:"latitude"`
	MetroCode      int     `json:"metro_code"`
}

type Names

type Names struct {
	ES   string `json:"es"`
	JA   string `json:"ja"`
	PTBR string `json:"pt-BR"`
	EN   string `json:"en"`
	FR   string `json:"fr"`
	RU   string `json:"ru"`
	ZHCN string `json:"zh-CN"`
	DE   string `json:"de"`
}

type Postal

type Postal struct {
	Code string `json:"code"`
}

type RegisteredCountry

type RegisteredCountry struct {
	GeonameId ID    `json:"geoname_id"`
	Names     Names `json:"names"`
}

type Subdivision

type Subdivision struct {
	GeonameId ID     `json:"geoname_id"`
	Names     Names  `json:"names"`
	IsoCode   string `json:"iso_code"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL