operate

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DataSep          = "\t"
	DataConditionSep = ","
)
View Source
const (
	SelectorGroupSep    = "|"
	SelectorFieldSep    = ","
	SelectorRuleSep     = ":"
	SelectorValueNot    = "!"
	SelectorValueOr     = "/"
	SelectorValReplace  = "="
	SelectorWildcardArg = "*"
)

Constants used as separators and rules in field selectors.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataRewriter

type DataRewriter struct {

	// Data maps conditions to rewrite units. Multiple fields can be matched in sequence to determine the rewrite rule.
	// level 1: map[string] list of fields, multiple fields separated by DataConditionSep, each rewrite needs to match all the fields.
	// level 2: map[string] Match condition, multiple fields separated by DataConditionSep.
	// level 3: []RewriteUnit rewrite unit, rewrites sequentially, in the order it was loaded
	Data map[string]map[string][]RewriteUnit
}

DataRewriter is responsible for rewriting data based on the provided rules. It uses predefined conditions to determine which data entries should be modified.

func NewDataRewriter

func NewDataRewriter() *DataRewriter

NewDataRewriter initializes and returns a new DataRewriter.

func (*DataRewriter) Do

func (d *DataRewriter) Do(info *model.IPInfo) error

Do applies the data rewriting rules to the provided IPInfo.

func (*DataRewriter) LoadFile

func (d *DataRewriter) LoadFile(file string) error

LoadFile loads the rewriting rules from a file.

func (*DataRewriter) LoadFiles

func (d *DataRewriter) LoadFiles(files []string) error

LoadFiles loads the rewriting rules from a list of files.

func (*DataRewriter) LoadString

func (d *DataRewriter) LoadString(data ...string)

LoadString loads rewriting rules from the provided data strings.

type FieldSelector

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

FieldSelector represents a selector that can be applied to IPInfo to select and modify fields.

func NewFieldSelector

func NewFieldSelector(meta *model.Meta, arg string) (*FieldSelector, error)

NewFieldSelector initializes a FieldSelector based on the given argument string. It supports a custom string format to determine which fields to select and under which conditions. The format is: <fields>[|<rule1>:<fields>|<rule2>:<fields>|<default fields>] MAKE SURE that the incoming meta comes from StandardReader, not DB Reader, since it may modify the *model.Meta. Refer to the provided examples in the function comments for more details.

func (*FieldSelector) Do

func (f *FieldSelector) Do(info *model.IPInfo) error

Do applies the field selector rules to an IPInfo object, selecting and modifying fields as necessary.

func (*FieldSelector) Fields

func (f *FieldSelector) Fields() []string

Fields returns the list of fields currently set in the field selector.

type FieldSelectorRule

type FieldSelectorRule struct {
	Condition     url.Values
	Fields        []string
	ReplaceFields map[string]string
}

FieldSelectorRule represents a single rule within a FieldSelector.

func (*FieldSelectorRule) IsMatch

func (r *FieldSelectorRule) IsMatch(info *model.IPInfo) bool

IsMatch determines if the given IPInfo matches the conditions set in the rule.

type IPOperateChain

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

IPOperateChain represents a chain of IPOperateFuncs, organized to be executed in the order they are added.

func NewIPOperateChain

func NewIPOperateChain() *IPOperateChain

NewIPOperateChain initializes and returns a new IPOperateChain.

func (*IPOperateChain) Do

func (c *IPOperateChain) Do(info *model.IPInfo) error

Do executes all the operations in the chain on the given IPInfo.

func (*IPOperateChain) Use

func (c *IPOperateChain) Use(f IPOperateFunc)

Use adds an IPOperateFunc to the end of the operation chain.

type IPOperateFunc

type IPOperateFunc func(info *model.IPInfo) error

IPOperateFunc defines a function type for operations on IPInfo, such as filtering fields, rewriting data, supplementing data, etc.

type RewriteUnit

type RewriteUnit struct {
	Condition url.Values // Condition to match for rewriting
	Replace   url.Values // Content to replace if the condition is matched
}

RewriteUnit is a structure that holds the condition to match and the content to replace.

type Translator added in v0.2.1

type Translator struct {
	TargetLang string // Target language for translation
}

Translator is a structure that provides functionality to translate IPInfo's geolocation fields.

func NewTranslator added in v0.2.1

func NewTranslator(targetLang string) (*Translator, error)

NewTranslator initializes a new Translator for a given target language.

func (*Translator) Do added in v0.2.1

func (t *Translator) Do(info *model.IPInfo) error

Do translates the geolocation fields in the provided IPInfo instance.\

Jump to

Keyboard shortcuts

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