conf

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package conf contains methods and structures for configuration.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cfg

type Cfg struct {
	Host          string   `json:"host"`
	Port          uint     `json:"port"`
	Db            string   `json:"db"`
	IgnoreHeaders []string `json:"ignore_headers"`
	IPHeader      string   `json:"ip_header"`
	CacheSize     int      `json:"cache_size"`
	// contains filtered or unexported fields
}

Cfg is configuration settings struct.

func New

func New(filename string) (*Cfg, error)

New returns new rates configuration.

func (*Cfg) Addr

func (c *Cfg) Addr() string

Addr returns service's net address.

func (*Cfg) Close

func (c *Cfg) Close() error

Close closes db storage file.

func (*Cfg) GetCity

func (c *Cfg) GetCity(host string) (*geoip2.City, error)

GetCity returns city info found by IP address.

func (*Cfg) GetHeaders added in v1.0.0

func (c *Cfg) GetHeaders(r *http.Request) []StrParam

GetHeaders returns sorted request headers excluding ignored values.

func (*Cfg) GetIP

func (c *Cfg) GetIP(r *http.Request) (string, error)

GetIP return string IP address.

func (*Cfg) GetParams added in v1.0.0

func (c *Cfg) GetParams(r *http.Request) []StrParam

GetParams returns sorted request parameters.

func (*Cfg) Info added in v1.4.0

func (c *Cfg) Info(r *http.Request) (*IPInfo, error)

Info returns base info about request.

type IPInfo added in v1.4.0

type IPInfo struct {
	IP        string    `xml:"ip" json:"ip"`
	Country   string    `xml:"country" json:"country"`
	City      string    `xml:"city" json:"city"`
	Longitude float64   `xml:"longitude" json:"longitude"`
	Latitude  float64   `xml:"latitude" json:"latitude"`
	UTCTime   string    `xml:"utc_time" json:"utc_time"`
	TimeZone  string    `xml:"time_zone" json:"time_zone"`
	Language  string    `xml:"language" json:"language"`
	Timestamp time.Time `xml:"-" json:"-"`
}

IPInfo is IP and related info for response.

func (*IPInfo) LocalDateTime added in v1.7.0

func (i *IPInfo) LocalDateTime() (string, string)

LocalDateTime returns separated local date and time strings or "-" if error.

func (*IPInfo) LocalTime added in v1.5.0

func (i *IPInfo) LocalTime() string

LocalTime returns local time in RFC3339 format or "-" if error.

func (*IPInfo) Location added in v1.5.0

func (i *IPInfo) Location() string

Location returns location string.

type StrParam added in v1.0.0

type StrParam struct {
	Name  string
	Value string
}

StrParam is common struct for headers and form params.

Jump to

Keyboard shortcuts

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