From 6f88811c79c39953a8d92debed3b913ba6984ec8 Mon Sep 17 00:00:00 2001 From: MinatoHikari <35342316+MinatoHikari@users.noreply.github.com> Date: Sun, 30 May 2021 17:19:36 +0800 Subject: [PATCH] custom port --- config.go | 12 ++++++++++++ config.toml.example | 3 ++- main.go | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 93d97de..6aafc5b 100644 --- a/config.go +++ b/config.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "github.com/spf13/viper" + "strings" ) // Config 配置. @@ -54,3 +55,14 @@ func GetToken() *string { return &token } + +func GetPort() string { + port := Config.GetString("port") + if port != "" { + port = strings.Join([]string{":", port}, "") + } else { + port = ":8079" + } + + return port +} diff --git a/config.toml.example b/config.toml.example index c4366b8..77e92d1 100644 --- a/config.toml.example +++ b/config.toml.example @@ -3,4 +3,5 @@ script = "build:dev" dist = "./dist" token = "xxxxxxxxxxxxxx" branch = "main" -logPath = "/usr/local/var/webhook.log" \ No newline at end of file +logPath = "/usr/local/var/webhook.log" +port = "8079" \ No newline at end of file diff --git a/main.go b/main.go index 14b8ff4..ccef782 100644 --- a/main.go +++ b/main.go @@ -29,7 +29,7 @@ func main() { InitLog(app) - err := app.Listen(":8079") + err := app.Listen(GetPort()) if err != nil { fmt.Println("service start failed:", err) }