diff options
| author | Loyalsoldier <[email protected]> | 2024-07-08 17:13:26 +0800 |
|---|---|---|
| committer | Loyalsoldier <[email protected]> | 2024-07-08 17:13:26 +0800 |
| commit | 130d27a531410485ccc37ca41c1dffe46a64c442 (patch) | |
| tree | d9b5417c442b271f45a4c12fc178519ce2b39ae5 /lib/instance.go | |
| parent | 18e9f1aafac9bdb2783daa47f9a07c67e780f554 (diff) | |
Feat: add merge command
merge command can merge plaintext IP & CIDR from standard input, then print the merged result to standard output
usage example:
curl https://example.com/path/to/your/plaintext/cidr.txt | geoip merge
cat ./path/to/your/plaintext/cidr.txt | geoip merge
Diffstat (limited to 'lib/instance.go')
| -rw-r--r-- | lib/instance.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/instance.go b/lib/instance.go index b1b1337d..79949c0f 100644 --- a/lib/instance.go +++ b/lib/instance.go @@ -49,6 +49,22 @@ func (i *Instance) Init(configFile string) error { return nil } +func (i *Instance) InitFromBytes(content []byte) error { + if err := json.Unmarshal(content, &i.config); err != nil { + return err + } + + for _, input := range i.config.Input { + i.input = append(i.input, input.converter) + } + + for _, output := range i.config.Output { + i.output = append(i.output, output.converter) + } + + return nil +} + func (i *Instance) Run() error { if len(i.input) == 0 || len(i.output) == 0 { return errors.New("input type and output type must be specified") |
