xq před 1 rokem
rodič
revize
a06e6f1072
2 změnil soubory, kde provedl 9 přidání a 11 odebrání
  1. 3 0
      README.md
  2. 6 11
      main.go

+ 3 - 0
README.md

@@ -28,12 +28,15 @@ GLOBAL OPTIONS:
 
 ```shell
 GOOS=linux GOARCH=amd64 go build -o webup-linux-amd64 -a -ldflags '-w -s -extldflags "-static"' main.go
+
 GOOS=linux GOARCH=arm64 go build -o webup-linux-arm64 -a -ldflags '-w -s -extldflags "-static"' main.go
 
 GOOS=darwin GOARCH=amd64 go build -o webup-darwin-amd64 -a -ldflags '-w -s -extldflags "-static"' main.go
+
 GOOS=darwin GOARCH=arm64 go build -o webup-darwin-arm64 -a -ldflags '-w -s -extldflags "-static"' main.go
 
 GOOS=windows GOARCH=arm64 go build -o webup-windows-arm64.exe -a -ldflags '-w -s -extldflags "-static"' main.go
+
 GOOS=windows GOARCH=amd64 go build -o webup-windows-amd64.exe -a -ldflags '-w -s -extldflags "-static"' main.go
 
 ```

+ 6 - 11
main.go

@@ -1,7 +1,6 @@
 package main
 
 import (
-	"errors"
 	"io/ioutil"
 	"net"
 	"net/http"
@@ -50,21 +49,22 @@ func getCurrentAbPathByExecutable() string {
 	return res
 }
 
-func getClientIp() (string, error) {
+func getClientIp() {
 	addrs, err := net.InterfaceAddrs()
 
 	if err != nil {
-		return "", err
+		log.Errorf("Error getClientIp %v", err)
+		return
 	}
 
 	for _, address := range addrs {
 		if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
 			if ipnet.IP.To4() != nil {
-				return ipnet.IP.String(), nil
+				//return ipnet.IP.String(), nil
+				log.Infof("HTTP://" + ipnet.IP.String() + ":" + port)
 			}
 		}
 	}
-	return "", errors.New("Can not find the client ip address!")
 }
 
 func walkDir(filestr string) ([]string, error) {
@@ -264,12 +264,7 @@ func getFiles(c *gin.Context) {
 }
 
 func doWork() {
-	ip, err := getClientIp()
-	if err != nil {
-		log.Errorf("Error getClientIp %v", err)
-		return
-	}
-	log.Infof("HTTP://" + ip + ":" + port)
+	getClientIp()
 
 	r := gin.Default()
 	//加载静态文件