config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: Apache-2.0, MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides TOML configuration parsing and validation for mmdbconvert.

Index

Constants

View Source
const (

	// IPv6BucketTypeString stores IPv6 bucket values as hex strings.
	IPv6BucketTypeString = "string"
	// IPv6BucketTypeInt stores IPv6 bucket values as int64 (first 60 bits).
	IPv6BucketTypeInt = "int"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVConfig

type CSVConfig struct {
	Delimiter      string `toml:"delimiter"`        // Field delimiter (default: ",")
	IncludeHeader  *bool  `toml:"include_header"`   // Include column headers (default: true)
	IPv4BucketSize int    `toml:"ipv4_bucket_size"` // Bucket prefix length for IPv4 (default: 16)
	IPv6BucketSize int    `toml:"ipv6_bucket_size"` // Bucket prefix length for IPv6 (default: 16)
	IPv6BucketType string `toml:"ipv6_bucket_type"` // "string" or "int" (default: "string")
}

CSVConfig defines CSV output options.

type Column

type Column struct {
	Name       mmdbtype.String `toml:"name"`        // Output column name
	Database   string          `toml:"database"`    // Database to read from (references Database.Name)
	Path       Path            `toml:"path"`        // Path segments to the field
	OutputPath *Path           `toml:"output_path"` // Path segments for MMDB output (defaults to [name])
	Type       string          `toml:"type"`        // Optional type hint: "string", "int64", "float64", "bool", "binary" (Parquet only)
}

Column defines a data column mapping from MMDB to output.

type Config

type Config struct {
	Output       OutputConfig  `toml:"output"`
	Network      NetworkConfig `toml:"network"`
	Databases    []Database    `toml:"databases"`
	Columns      []Column      `toml:"columns"`
	DisableCache bool          `toml:"disable_cache"` // Disable MMDB unmarshaler caching (default: false)
}

Config represents the complete configuration file structure.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads and parses a TOML configuration file.

type Database

type Database struct {
	Name string `toml:"name"` // Identifier for referencing in columns
	Path string `toml:"path"` // Path to MMDB file
}

Database defines an MMDB database source.

type MMDBConfig

type MMDBConfig struct {
	DatabaseType            string            `toml:"database_type"`             // Database type (e.g., "GeoIP2-City")
	Description             map[string]string `toml:"description"`               // Descriptions by language
	Languages               []string          `toml:"languages"`                 // List of languages (auto-populated from description if empty)
	RecordSize              *int              `toml:"record_size"`               // 24, 28, or 32 (default: 28)
	IncludeReservedNetworks *bool             `toml:"include_reserved_networks"` // Include reserved networks (default: false)
}

MMDBConfig defines MMDB output options.

type NetworkColumn

type NetworkColumn struct {
	Name mmdbtype.String `toml:"name"` // Column name
	Type string          `toml:"type"` // "cidr", "start_ip", "end_ip", "start_int", "end_int"
}

NetworkColumn defines a network column in the output.

type NetworkConfig

type NetworkConfig struct {
	Columns []NetworkColumn `toml:"columns"`
}

NetworkConfig defines network column configuration.

type OutputConfig

type OutputConfig struct {
	Format           string        `toml:"format"`  // "csv", "parquet", or "mmdb"
	File             string        `toml:"file"`    // Output file path
	CSV              CSVConfig     `toml:"csv"`     // CSV-specific options
	Parquet          ParquetConfig `toml:"parquet"` // Parquet-specific options
	MMDB             MMDBConfig    `toml:"mmdb"`    // MMDB-specific options
	IPv4File         string        `toml:"ipv4_file"`
	IPv6File         string        `toml:"ipv6_file"`
	IncludeEmptyRows *bool         `toml:"include_empty_rows"` // Include rows with no MMDB data (default: false)
}

OutputConfig defines output file settings.

type ParquetConfig

type ParquetConfig struct {
	Compression    string `toml:"compression"`      // "none", "snappy", "gzip", "lz4", "zstd" (default: "snappy")
	RowGroupSize   int    `toml:"row_group_size"`   // Rows per row group (default: 500000)
	IPv4BucketSize int    `toml:"ipv4_bucket_size"` // Bucket prefix length for IPv4 (default: 16)
	IPv6BucketSize int    `toml:"ipv6_bucket_size"` // Bucket prefix length for IPv6 (default: 16)
	IPv6BucketType string `toml:"ipv6_bucket_type"` // "string" or "int" (default: "string")
}

ParquetConfig defines Parquet output options.

type Path

type Path []any

Path represents the decoded path segments for MMDB lookup.

func (*Path) Segments

func (p *Path) Segments() []any

Segments returns a copy of the path segments suitable for DecodePath.

func (*Path) UnmarshalTOML

func (p *Path) UnmarshalTOML(v any) error

UnmarshalTOML implements toml.Unmarshaler allowing mixed string/int arrays. Empty arrays are allowed - path = [] means "copy entire record".

Jump to

Keyboard shortcuts

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