giplib: separate functions in lib and app

Signed-off-by: Nagy Károly Gábriel <k@jpi.io>
This commit is contained in:
2019-01-19 22:15:36 +02:00
parent 8471fcd3de
commit af71b64160
2 changed files with 107 additions and 32 deletions
+45
View File
@@ -0,0 +1,45 @@
package main
import (
"flag"
"fmt"
"git.jpi.io/karasz/gip/giplib"
"os"
)
var (
//Version contains the git hashtag injected by make
Version = "N/A"
//BuildTime contains the build timestamp injected by make
BuildTime = "N/A"
)
func main() {
var all bool
ptr4 := flag.Bool("4", false, "return only IPv4")
ptr6 := flag.Bool("6", false, "return only IPv6")
version := flag.Bool("v", false, "return version")
flag.Parse()
if *version {
fmt.Println(Version, " built on ", BuildTime)
os.Exit(0)
}
if *ptr4 == *ptr6 {
all = true
}
if all {
fmt.Println(giplib.GetIPv4())
fmt.Println(giplib.GetIPv6())
os.Exit(0)
}
if *ptr4 {
fmt.Println(giplib.GetIPv4())
}
if *ptr6 {
fmt.Println(giplib.GetIPv6())
}
}