-
Notifications
You must be signed in to change notification settings - Fork 668
/
convert.go
36 lines (29 loc) · 836 Bytes
/
convert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"log"
"github.com/Loyalsoldier/geoip/lib"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(convertCmd)
convertCmd.PersistentFlags().StringP("config", "c", "config.json", "URI of the JSON format config file, support both local file path and remote HTTP(S) URL")
}
var convertCmd = &cobra.Command{
Use: "convert",
Aliases: []string{"conv"},
Short: "Convert geoip data from one format to another by using config file",
Run: func(cmd *cobra.Command, args []string) {
configFile, _ := cmd.Flags().GetString("config")
log.Println("Use config:", configFile)
instance, err := lib.NewInstance()
if err != nil {
log.Fatal(err)
}
if err := instance.InitConfig(configFile); err != nil {
log.Fatal(err)
}
if err := instance.Run(); err != nil {
log.Fatal(err)
}
},
}