From fc0945798e10d95d84892ea67e6db326dab66530 Mon Sep 17 00:00:00 2001 From: Nike Date: Fri, 26 Apr 2024 07:47:34 +0300 Subject: [PATCH] feat: added env param `PORT` --- README.md | 2 +- cmd/go-ks/main.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 15d1567..1eb11dd 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ curl -X POST http://localhost:8989/calculate \ ### Or 3. Use integration test: ```bash -go test -v +go test -v ./... ``` output should be: ```txt diff --git a/cmd/go-ks/main.go b/cmd/go-ks/main.go index 1c5544c..8d9ecfe 100644 --- a/cmd/go-ks/main.go +++ b/cmd/go-ks/main.go @@ -1,14 +1,22 @@ package main import ( + "fmt" "log" "net/http" + "os" "github.com/Nikolay200669/go-ks/internal/app/application" iface "github.com/Nikolay200669/go-ks/internal/app/interfaces/http" ) func main() { + port := os.Getenv("PORT") + if port == "" { + port = "8989" + } + addr := fmt.Sprintf(":%s", port) + // Initialize the CalculateService calculateService := &application.CalculateService{} @@ -16,5 +24,5 @@ func main() { router := iface.SetupRouter(calculateService) // Run the server - log.Fatal(http.ListenAndServe(":8989", router)) + log.Fatal(http.ListenAndServe(addr, router)) }