server

package
v0.0.0-...-5e0ec4f Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: MIT, MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ASRecord

type ASRecord struct {
	Number uint   `json:"number"`
	Name   string `json:"name"`
}

type ApiHandler

type ApiHandler struct {
	// contains filtered or unexported fields
}

type ContinentRecord

type ContinentRecord struct {
	Code      string `json:"code"`
	Name      string `json:"name"`
	SubRegion string `json:"sub_region"`
}

type CountryRecord

type CountryRecord struct {
	Code                string            `json:"code"`
	CIOC                string            `json:"cioc"`
	CCN3                string            `json:"ccn3"`
	CallCode            []string          `json:"call_code"`
	InternationalPrefix string            `json:"international_prefix"`
	Capital             string            `json:"capital"`
	Name                string            `json:"name"`
	FullName            string            `json:"full_name"`
	Area                float64           `json:"area"`
	Borders             []string          `json:"borders"`
	Latitude            float64           `json:"latitude"`
	Longitude           float64           `json:"longitude"`
	MaxLatitude         float64           `json:"max_latitude"`
	MaxLongitude        float64           `json:"max_longitude"`
	MinLatitude         float64           `json:"min_latitude"`
	MinLongitude        float64           `json:"min_longitude"`
	Currency            []*CurrencyRecord `json:"currency"`
	Continent           *ContinentRecord  `json:"continent"`
}

type CurrencyRecord

type CurrencyRecord struct {
	Code string `json:"code"`
	Name string `json:"name"`
}

type GeoIpQuery

func (*GeoIpQuery) Record

func (q *GeoIpQuery) Record(ip net.IP, lang string, request *http.Request) *ResponseRecord

func (*GeoIpQuery) Translate

func (q *GeoIpQuery) Translate(names map[string]string, lang string) string

func (*GeoIpQuery) TranslateCountry

func (q *GeoIpQuery) TranslateCountry(t map[string]gountries.BaseLang, lang string) *gountries.BaseLang

type LanguageRecord

type LanguageRecord struct {
	Language string `json:"language"`
	Region   string `json:"region"`
	Tag      string `json:"tag"`
}

type LocationRecord

type LocationRecord struct {
	RegionCode     string         `json:"region_code"`
	RegionName     string         `json:"region_name"`
	City           string         `json:"city"`
	ZipCode        string         `json:"zip_code"`
	TimeZone       string         `json:"time_zone"`
	Longitude      float64        `json:"longitude"`
	Latitude       float64        `json:"latitude"`
	AccuracyRadius uint           `json:"accuracy_radius"`
	MetroCode      uint           `json:"metro_code"`
	Country        *CountryRecord `json:"country"`
}

type NetworkRecord

type NetworkRecord struct {
	IP        string    `json:"ip"`
	AS        *ASRecord `json:"as"`
	Isp       string    `json:"isp"`
	Domain    string    `json:"domain"`
	Tld       []string  `json:"tld"`
	Bot       bool      `json:"bot"`
	Tor       bool      `json:"tor"`
	Proxy     bool      `json:"proxy"`
	ProxyType string    `json:"proxy_type"`
	LastSeen  uint      `json:"last_seen"`
	UsageType string    `json:"usage_type"`
}

type RateLimit

type RateLimit struct {
	Limit    rate.Limit
	Burst    int
	Interval time.Duration
	Mutex    *sync.RWMutex
	Visitors map[string]*Visitor
}

func NewRateLimit

func NewRateLimit(limit int, burst int, interval time.Duration) *RateLimit

func (*RateLimit) AddIP

func (i *RateLimit) AddIP(ip string) *rate.Limiter

AddIP creates a new rate limiter and adds it to the ips map, using the IP address as the key

func (*RateLimit) GetLimiter

func (i *RateLimit) GetLimiter(ip string) *rate.Limiter

GetLimiter returns the rate limiter for the provided IP address if it exists. Otherwise calls AddIP to add IP address to the map

type ResponseRecord

type ResponseRecord struct {
	XMLName  xml.Name        `xml:"Response" json:"-"`
	Network  *NetworkRecord  `json:"network"`
	Location *LocationRecord `json:"location"`
	System   *SystemRecord   `json:"system,omitempty"`
	User     *UserRecord     `json:"user,omitempty"`
}

func (*ResponseRecord) String

func (rr *ResponseRecord) String() string

type Server

type Server struct {
	Config *config.Config

	Host string
	Port int

	RateLimit *RateLimit
	Visitors  map[string]*Visitor
	Mutex     sync.Mutex

	Api *ApiHandler
}

func NewServerConfig

func NewServerConfig(c *config.Config) *Server

func (*Server) IpLookUp

func (s *Server) IpLookUp(writer writerFunc) http.HandlerFunc

func (*Server) NewHandler

func (s *Server) NewHandler() (http.Handler, error)

NewHandler creates an http handler for the geoip server that can be embedded in other servers.

func (*Server) Start

func (s *Server) Start()

type SystemRecord

type SystemRecord struct {
	OS        string `json:"os"`
	Browser   string `json:"browser"`
	Version   string `json:"version"`
	OSVersion string `json:"os_version"`
	Device    string `json:"device"`
	Mobile    bool   `json:"mobile"`
	Tablet    bool   `json:"tablet"`
	Desktop   bool   `json:"desktop"`
}

type UserRecord

type UserRecord struct {
	Language *LanguageRecord `json:"language"`
}

type Visitor

type Visitor struct {
	// contains filtered or unexported fields
}

Create a custom visitor struct which holds the rate limiter for each visitor and the last time that the visitor was seen.

Jump to

Keyboard shortcuts

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