浏览代码

Added verbal mode and removed aws dependencies

TC 3 年之前
父节点
当前提交
1f29e0a977
共有 1 个文件被更改,包括 20 次插入4 次删除
  1. 20 4
      main.go

+ 20 - 4
main.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"flag"
 	"fmt"
 	"io/ioutil"
 	"log"
@@ -9,17 +10,32 @@ import (
 	"strings"
 )
 
+var (
+	verbal = flag.Bool("v", true, "Enable verbal output")
+)
+
 func main() {
-	//Create a dummy request
+	flag.Parse()
 	publicIp := strings.TrimSpace(getPublicIP())
-	fmt.Println("Your public IP address is: ", publicIp)
 	domains := GetFreeDomain(publicIp)
-	fmt.Println("Your free domain assigned by ISP is: ", domains)
+	if *verbal {
+		fmt.Println("Your public IP address is: ", publicIp)
+		fmt.Println("Your free domain assigned by ISP is: ", domains)
+	} else {
+		if len(domains) > 0 {
+			out := domains[0]
+			if out[len(out)-1:] == "." {
+				out = out[:len(out)-1]
+			}
+			fmt.Println(out)
+		}
+	}
+
 }
 
 func getPublicIP() string {
 	//http://checkip.amazonaws.com/
-	resp, err := http.Get("http://checkip.amazonaws.com/")
+	resp, err := http.Get("https://api.ipify.org/")
 	if err != nil {
 		log.Fatalln(err)
 	}