convert

package
v0.0.0-...-146c658 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package convert transforms a GeoIP2/GeoLite2 CSV to various formats.

Index

Constants

View Source
const (
	STR_START_IP string = "start_ip_int"
	STR_END_IP   string = "end_ip_int"
)

Variables

This section is empty.

Functions

func ConvertFile

func ConvertFile(
	config *Config,
	inputFile string,
	outputFile string,
) error

ConvertFile converts the MaxMind GeoIP2 or GeoLite2 CSV file `inputFile` to `outputFile` file using a different representation of the network. The representation can be specified by setting one or more of `cidr`, `ipRange`, `intRange` or `hexRange` to true. If none of these are set to true, it will strip off the network information.

func PrintMemUsage

func PrintMemUsage()

Types

type BaseFieldMapper

type BaseFieldMapper struct {
	FieldConfig
	// contains filtered or unexported fields
}

func (*BaseFieldMapper) GetConfig

func (m *BaseFieldMapper) GetConfig() *FieldConfig

func (*BaseFieldMapper) GetTargetFieldComponents

func (m *BaseFieldMapper) GetTargetFieldComponents() []string

func (*BaseFieldMapper) Preprocess

func (m *BaseFieldMapper) Preprocess(s string) string

func (*BaseFieldMapper) ShouldOmitRecord

func (m *BaseFieldMapper) ShouldOmitRecord(input string) bool

func (*BaseFieldMapper) ShouldOmitValue

func (m *BaseFieldMapper) ShouldOmitValue(input string) bool

type BooleanFieldMapper

type BooleanFieldMapper struct {
	BaseFieldMapper
}

func NewBooleanFieldMapper

func NewBooleanFieldMapper(fc *FieldConfig) *BooleanFieldMapper

func (*BooleanFieldMapper) Map

func (m *BooleanFieldMapper) Map(input string) (mmdbtype.DataType, error)

type Config

type Config struct {
	DatabaseType  string         `yaml:"databaseType"`
	RecordSize    uint8          `yaml:"recordSize"`
	UseValueCache bool           `yaml:"useValueCache"`
	Fields        []*FieldConfig `yaml:"fields"`
}

func NewConfig

func NewConfig(filePath string) (*Config, error)

func (*Config) Validate

func (c *Config) Validate() error

type Converter

type Converter struct {
	// contains filtered or unexported fields
}

func NewConverter

func NewConverter(config *Config, input io.Reader, inputSize int64) *Converter

func (*Converter) Convert

func (c *Converter) Convert(
	output io.Writer,
) error

Convert writes the MaxMind GeoIP2 or GeoLite2 CSV in the `input` io.Reader to the Writer `output`.

type FieldConfig

type FieldConfig struct {
	Name           string            `yaml:"name"`
	Target         string            `yaml:"target"`
	Type           string            `yaml:"type"`
	Capitalization string            `yaml:"capitalization"`
	Translate      map[string]string `yaml:"translate"`
	IgnoreEmpty    bool              `yaml:"ignoreEmpty"`
	Critical       bool              `yaml:"critical"`
	OmitZeroValue  bool              `yaml:"omitZeroValue"`
	FieldMapper    FieldMapper
}

func (*FieldConfig) Validate

func (f *FieldConfig) Validate() error

type FieldMapper

type FieldMapper interface {
	Map(string) (mmdbtype.DataType, error)
	ShouldOmitRecord(string) bool
	ShouldOmitValue(string) bool
	GetConfig() *FieldConfig
	GetTargetFieldComponents() []string
}

func NewFieldMapper

func NewFieldMapper(f *FieldConfig) (FieldMapper, error)

type Float32FieldMapper

type Float32FieldMapper struct {
	BaseFieldMapper
}

func NewFloat32FieldMapper

func NewFloat32FieldMapper(fc *FieldConfig) *Float32FieldMapper

func (*Float32FieldMapper) Map

func (m *Float32FieldMapper) Map(input string) (mmdbtype.DataType, error)

type Float64FieldMapper

type Float64FieldMapper struct {
	BaseFieldMapper
}

func NewFloat64FieldMapper

func NewFloat64FieldMapper(fc *FieldConfig) *Float64FieldMapper

func (*Float64FieldMapper) Map

func (m *Float64FieldMapper) Map(input string) (mmdbtype.DataType, error)

type Int32FieldMapper

type Int32FieldMapper struct {
	BaseFieldMapper
}

func NewInt32FieldMapper

func NewInt32FieldMapper(fc *FieldConfig) *Int32FieldMapper

func (*Int32FieldMapper) Map

func (m *Int32FieldMapper) Map(input string) (mmdbtype.DataType, error)

type MapFunc

type MapFunc func([]string) mmdbRow

type RowMapper

type RowMapper struct {
	// contains filtered or unexported fields
}

func NewMapper

func NewMapper(config *Config, header []string) (*RowMapper, error)

func (*RowMapper) Map

func (m *RowMapper) Map(data []string) (mmdbRow, error)

type StringFieldMapper

type StringFieldMapper struct {
	BaseFieldMapper
	// contains filtered or unexported fields
}

func NewStringFieldMapper

func NewStringFieldMapper(fc *FieldConfig) *StringFieldMapper

func (*StringFieldMapper) Map

func (m *StringFieldMapper) Map(input string) (mmdbtype.DataType, error)

type Uint16FieldMapper

type Uint16FieldMapper struct {
	BaseFieldMapper
}

func NewUint16FieldMapper

func NewUint16FieldMapper(fc *FieldConfig) *Uint16FieldMapper

func (*Uint16FieldMapper) Map

func (m *Uint16FieldMapper) Map(input string) (mmdbtype.DataType, error)

type Uint32FieldMapper

type Uint32FieldMapper struct {
	BaseFieldMapper
}

func NewUint32FieldMapper

func NewUint32FieldMapper(fc *FieldConfig) *Uint32FieldMapper

func (*Uint32FieldMapper) Map

func (m *Uint32FieldMapper) Map(input string) (mmdbtype.DataType, error)

type Uint64FieldMapper

type Uint64FieldMapper struct {
	BaseFieldMapper
}

func NewUint64FieldMapper

func NewUint64FieldMapper(fc *FieldConfig) *Uint64FieldMapper

func (*Uint64FieldMapper) Map

func (m *Uint64FieldMapper) Map(input string) (mmdbtype.DataType, error)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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