-
Notifications
You must be signed in to change notification settings - Fork 669
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
old usage: geoip -l new usage: geoip list old usage: geoip -c config.json new usage: geoip convert -c config.json
- Loading branch information
1 parent
8c55b32
commit ad3e4c3
Showing
7 changed files
with
160 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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.Init(configFile); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if err := instance.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/Loyalsoldier/geoip/lib" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(listCmd) | ||
} | ||
|
||
var listCmd = &cobra.Command{ | ||
Use: "list", | ||
Aliases: []string{"l", "ls"}, | ||
Short: "List all available input and output formats", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
lib.ListInputConverter() | ||
println() | ||
lib.ListOutputConverter() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,21 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
|
||
"github.com/Loyalsoldier/geoip/lib" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
list = flag.Bool("l", false, "List all available input and output formats") | ||
configFile = flag.String("c", "config.json", "URI of the JSON format config file, support both local file path and remote HTTP(S) URL") | ||
) | ||
var rootCmd = &cobra.Command{ | ||
Use: "geoip", | ||
Short: "geoip is a convenient tool to merge, convert and lookup IP & CIDR from various formats of geoip data.", | ||
CompletionOptions: cobra.CompletionOptions{ | ||
HiddenDefaultCmd: true, | ||
}, | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
if *list { | ||
lib.ListInputConverter() | ||
lib.ListOutputConverter() | ||
return | ||
} | ||
|
||
instance, err := lib.NewInstance() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if err := instance.Init(*configFile); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
if err := instance.Run(); err != nil { | ||
if err := rootCmd.Execute(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |