ipread

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIpParseFailed = errors.New("failed to parse geo ip")
	ErrIpNotFound    = errors.New("ip not found")
)

Functions

func NewProviderRefreshModule added in v0.15.5

func NewProviderRefreshModule(name string, settings RefreshSettings) kernel.ModuleFactory

func NewReader

func NewReader(ctx context.Context, config cfg.Config, logger log.Logger, name string) (*reader, error)

func ProvideMemoryProvider

func ProvideMemoryProvider(name string) *memoryProvider

func ProvideReader added in v0.15.5

func ProvideReader(ctx context.Context, config cfg.Config, logger log.Logger, name string) (*reader, error)

func RefreshModuleFactory added in v0.15.5

func RefreshModuleFactory(ctx context.Context, config cfg.Config, logger log.Logger) (map[string]kernel.ModuleFactory, error)

Types

type GeoCity

type GeoCity struct {
	City        string `json:"city"`
	CountryCode string `json:"countryCode"`
	Ip          string `json:"ip"`
	TimeZone    string `json:"timeZone"`
}

type MaxmindSettings added in v0.15.5

type MaxmindSettings struct {
	Database     string `cfg:"database"`
	S3ClientName string `cfg:"s3_client_name"`
}

type MemoryRecord

type MemoryRecord struct {
	CountryIso string `cfg:"country_iso"`
	CityName   string `cfg:"city_name"`
	TimeZone   string `cfg:"time_zone"`
}

type Provider

type Provider interface {
	City(ipAddress net.IP) (*geoip2.City, error)
	Refresh(ctx context.Context) error
	Close() error
}

func NewMaxmindProvider

func NewMaxmindProvider(ctx context.Context, config cfg.Config, logger log.Logger, name string) (Provider, error)

func NewMemoryProvider

func NewMemoryProvider(_ context.Context, _ cfg.Config, _ log.Logger, name string) (Provider, error)

type ProviderFactory

type ProviderFactory func(ctx context.Context, config cfg.Config, logger log.Logger, name string) (Provider, error)

type Reader

type Reader interface {
	City(ipString string) (*GeoCity, error)
}

type ReaderSettings

type ReaderSettings struct {
	Provider string          `cfg:"provider" default:"maxmind"`
	Refresh  RefreshSettings `cfg:"refresh"`
}

type RefreshModule added in v0.15.5

type RefreshModule struct {
	kernel.BackgroundModule
	kernel.ServiceStage
	kernel.HealthCheckedModule
	// contains filtered or unexported fields
}

func (*RefreshModule) IsHealthy added in v0.15.5

func (m *RefreshModule) IsHealthy(ctx context.Context) (bool, error)

func (*RefreshModule) Run added in v0.15.5

func (m *RefreshModule) Run(ctx context.Context) (err error)

type RefreshSettings added in v0.15.5

type RefreshSettings struct {
	Enabled  bool          `cfg:"enabled" default:"false"`
	Interval time.Duration `cfg:"interval" default:"24h"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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