country

package
Version: v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2020 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrInternal errors.Error = 0xFFDA<<8 + iota
	ErrMissingRequiredField
	ErrBadCountryValueType
)

Errors returned by workers.

View Source
const UndefinedCountry = "ZZ"

UndefinedCountry is default country code. This means that a country is not defined.

Variables

This section is empty.

Functions

func GetCountry

func GetCountry(timeout uint64, url, field string) (string, error)

GetCountry returns country code by ip. Parses response in JSON format and returns a value of the field.

Types

type Config

type Config struct {
	Field   string
	Timeout uint64 // in milliseconds.
	// In a url template there should be an pattern {{ip}}.
	// Pattern {{ip}} will be replaced by a ip address of the agent.
	URLTemplate string
}

Config is the configuration for obtaining a country code.

func NewConfig

func NewConfig() *Config

NewConfig creates new configuration for obtaining a country code.

type ServerMock

type ServerMock struct {
	Server *httptest.Server
}

ServerMock it is mock for processing a request for country detection.

func NewServerMock

func NewServerMock(field, result string) *ServerMock

NewServerMock creates new ServerMock.

func (ServerMock) Close

func (s ServerMock) Close()

Close closed ServerMock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL