Kaynağa Gözat

bug.配置文件执行路径

kinve 1 yıl önce
ebeveyn
işleme
814bcb987d
4 değiştirilmiş dosya ile 11 ekleme ve 2 silme
  1. 1 0
      go.mod
  2. 2 0
      go.sum
  3. BIN
      main.exe
  4. 8 2
      main.go

+ 1 - 0
go.mod

@@ -15,6 +15,7 @@ require (
 	github.com/go-playground/validator/v10 v10.20.0 // indirect
 	github.com/goccy/go-json v0.10.2 // indirect
 	github.com/json-iterator/go v1.1.12 // indirect
+	github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
 	github.com/klauspost/cpuid/v2 v2.2.7 // indirect
 	github.com/leodido/go-urn v1.4.0 // indirect
 	github.com/mattn/go-isatty v0.0.20 // indirect

+ 2 - 0
go.sum

@@ -26,6 +26,8 @@ github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MG
 github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
 github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
 github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
+github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA=
+github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8=
 github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
 github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
 github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=

BIN
main.exe


+ 8 - 2
main.go

@@ -12,6 +12,7 @@ import (
 	"os/exec"
 
 	"github.com/gin-gonic/gin"
+	"github.com/kardianos/osext"
 )
 
 var config map[string]interface{}
@@ -65,7 +66,11 @@ func main() {
 		"stop_service":    []interface{}{"demo"},
 	}
 
-	configPath := "config.json"
+	folderPath, err := osext.ExecutableFolder()
+	if err != nil {
+		log.Fatal(err)
+	}
+	configPath := folderPath + "/config.json"
 	if len(os.Args) > 1 {
 		configPath = os.Args[1]
 	}
@@ -122,5 +127,6 @@ func main() {
 		c.Data(http.StatusOK, "text/html", []byte(text))
 	})
 
-	router.Run(fmt.Sprintf("%s:%.0f", config["host"], config["port"]))
+	router.Run(fmt.Sprintf("%s:%d", config["host"].(string), config["port"].(int)))
+
 }