Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type Manager
- func (m *Manager) Download(file, _url string) error
- func (m *Manager) GetIP(c *gin.Context)
- func (m *Manager) GetQuery(c *gin.Context)
- func (m *Manager) InitRouter()
- func (m *Manager) MyIP() (string, error)
- func (m *Manager) NoRoute(c *gin.Context)
- func (m *Manager) Pack(_format, file []string, _outputFormat, outputFile string) error
- func (m *Manager) ParseText(text string) (string, error)
- func (m *Manager) Service()
Constants ¶
const ( // OutputTypeText represents the text output format. OutputTypeText = "text" // OutputTypeJSON represents the JSON output format. OutputTypeJSON = "json" // OutputTypeAlfred represents the Alfred output format. OutputTypeAlfred = "alfred" // DefaultFields represents the default output fields. DefaultFields = "country,province,city,isp" )
Variables ¶
var DownloadMap = map[string]string{
"city.free.ipdb": "https://raw.githubusercontent.com/ipipdotnet/ipdb-go/master/city.free.ipdb",
"qqwry.dat": "https://github.com/metowolf/qqwry.dat/releases/download/20231025/qqwry.dat",
"zxipv6wry.db": "https://raw.githubusercontent.com/ZX-Inc/zxipdb-python/main/data/ipv6wry.db",
"GeoLite2-City.mmdb": "https://git.io/GeoLite2-City.mmdb",
"ip2region.xdb": "https://raw.githubusercontent.com/lionsoul2014/ip2region/master/data/ip2region.xdb",
"dbip-city-lite.mmdb": "https://download.db-ip.com/free/dbip-city-lite-2023-11.mmdb.gz",
"dbip-asn-lite.mmdb": "https://download.db-ip.com/free/dbip-asn-lite-2023-11.mmdb.gz",
}
var EFS embed.FS
EFS holds embedded file system data for static assets.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Common
// IPSDir specifies the working directory for IPS.
IPSDir string `mapstructure:"-"`
// Lang specifies the language for the output.
Lang string `mapstructure:"lang"`
// Find
// IPv4File specifies the file is IPv4 database.
IPv4File []string `mapstructure:"ipv4_file" default:"[\"qqwry.dat\"]"`
// IPv4Format specifies the format for IPv4 database.
IPv4Format []string `mapstructure:"ipv4_format"`
// IPv6File specifies the file is IPv6 database.
IPv6File []string `mapstructure:"ipv6_file" default:"[\"zxipv6wry.db\"]"`
// IPv6Format specifies the format for IPv6 database.
IPv6Format []string `mapstructure:"ipv6_format"`
// HybridMode specifies the operational mode of the HybridReader.
// It determines how the HybridReader processes and combines data from multiple IP database readers.
// Accepted values are "comparison" and "aggregation":
// - "comparison": Used for comparing data across different databases, where the output includes data from all readers.
// - "aggregation": Used for creating a unified view of data by aggregating and supplementing missing fields from multiple databases. (default)
HybridMode string `mapstructure:"hybrid_mode"`
// Fields lists the output fields.
// default is country, province, city, isp
Fields string `mapstructure:"fields" default:"country,province,city,isp"`
// UseDBFields indicates whether to use database fields. (default is common fields)
UseDBFields bool `mapstructure:"use_db_fields"`
// RewriteFiles lists the files for data rewriting.
RewriteFiles string `mapstructure:"rewrite_files"`
// OutputType specifies the type of the output. (default is text)
OutputType string `mapstructure:"output_type"`
// TextFormat specifies the format for text output.
// It supports %origin and %values parameters.
TextFormat string `mapstructure:"text_format" default:"%origin [%values] "`
// TextValuesSep specifies the separator for values in text output. (default is space)
TextValuesSep string `mapstructure:"text_values_sep" default:" "`
// JsonIndent indicates whether the JSON output should be indented.
JsonIndent bool `mapstructure:"json_indent"`
// Dump & Pack
// DPFields lists the output fields for dump and pack operations.
// default is empty, means all fields
DPFields string `mapstructure:"dp_fields"`
// DPRewriterFiles lists the files for rewriting during dump and pack operations.
DPRewriterFiles string `mapstructure:"dp_rewriter_files"`
// Database
// ReaderOption specifies the options for the reader.
ReaderOption string `mapstructure:"reader_option"`
// WriterOption specifies the options for the writer.
WriterOption string `mapstructure:"writer_option"`
// ReaderJobs specifies the number of concurrent jobs for the reader.
// It controls how many reading operations can be performed in parallel.
ReaderJobs int `mapstructure:"reader_jobs"`
// MyIP
// LocalAddr specifies the local address (in IP format) that should be used for outbound connections.
// Useful in systems with multiple network interfaces.
LocalAddr string `mapstructure:"local_addr"`
// MyIPCount defines the minimum number of detectors that should return the same IP
// for the IP to be considered as the system's public IP.
MyIPCount int `mapstructure:"myip_count" default:"3"`
// MyIPTimeoutS specifies the maximum duration (in seconds) to wait for the detectors to return an IP.
MyIPTimeoutS int `mapstructure:"myip_timeout_s"`
// Service
// Addr specifies the address for the service.
Addr string `mapstructure:"addr" default:":6860"`
}
Config represents the application's configuration.
func (*Config) ShowConfig ¶
type Manager ¶
type Manager struct {
// Conf holds the common configurations.
Conf *Config
// contains filtered or unexported fields
}
Manager is a command-line tool for IP operations.
func NewManager ¶
NewManager initializes and returns a new Manager instance.
func (*Manager) GetIP ¶ added in v0.2.5
GetIP handles the GET /v1/ip endpoint. It takes an IP as a query parameter and returns its associated information in JSON format. Example: GET /v1/ip?ip=<ip> Response: {}
func (*Manager) GetQuery ¶ added in v0.2.5
GetQuery handles the GET /v1/query endpoint. It takes a text string as a query parameter, parses it into segments, and returns the information associated with each segment. Example: GET /v1/query?text=<text> Response: {"items": [{},{}]}
func (*Manager) InitRouter ¶ added in v0.2.5
func (m *Manager) InitRouter()
InitRouter sets up routes and static file servers for the web service. It defines endpoints for API as well as serving static content.
func (*Manager) NoRoute ¶ added in v0.2.5
NoRoute handles 404 Not Found errors. If the request URL starts with "/api" or "/static", it responds with a JSON error. Otherwise, it redirects to the root path.
func (*Manager) Pack ¶
Pack reads data from a database file, processes it, and writes it to an output.