mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-23 16:58:31 +02:00
breaking: move maxmind config to config.providers
- moved maxmind to separate module - code refactored - simplified test
This commit is contained in:
10
internal/maxmind/types/city_info.go
Normal file
10
internal/maxmind/types/city_info.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package maxmind
|
||||
|
||||
type City struct {
|
||||
Location struct {
|
||||
TimeZone string `maxminddb:"time_zone"`
|
||||
} `maxminddb:"location"`
|
||||
Country struct {
|
||||
IsoCode string `maxminddb:"iso_code"`
|
||||
} `maxminddb:"country"`
|
||||
}
|
||||
33
internal/maxmind/types/config.go
Normal file
33
internal/maxmind/types/config.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package maxmind
|
||||
|
||||
import (
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/yusing/go-proxy/internal/gperr"
|
||||
"github.com/yusing/go-proxy/internal/logging"
|
||||
)
|
||||
|
||||
type (
|
||||
DatabaseType string
|
||||
Config struct {
|
||||
AccountID string `json:"account_id" validate:"required"`
|
||||
LicenseKey string `json:"license_key" validate:"required"`
|
||||
Database DatabaseType `json:"database" validate:"omitempty,oneof=geolite geoip2"`
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
MaxMindGeoLite DatabaseType = "geolite"
|
||||
MaxMindGeoIP2 DatabaseType = "geoip2"
|
||||
)
|
||||
|
||||
func (cfg *Config) Validate() gperr.Error {
|
||||
if cfg.Database == "" {
|
||||
cfg.Database = MaxMindGeoLite
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cfg *Config) Logger() *zerolog.Logger {
|
||||
l := logging.With().Str("database", string(cfg.Database)).Logger()
|
||||
return &l
|
||||
}
|
||||
9
internal/maxmind/types/ip_info.go
Normal file
9
internal/maxmind/types/ip_info.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package maxmind
|
||||
|
||||
import "net"
|
||||
|
||||
type IPInfo struct {
|
||||
IP net.IP
|
||||
Str string
|
||||
City *City
|
||||
}
|
||||
Reference in New Issue
Block a user