summaryrefslogtreecommitdiff
path: root/server.go
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-12-21 01:55:07 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-12-21 01:55:07 +0530
commit5336a9dfad7cb482ceeb92ae0d59eeca38986c5a (patch)
treed2274a9e6a6dbbfbfed137ccf945d5b9b9045351 /server.go
parent3f8958d179936e412d59c86acbffab4561ba1cba (diff)
server.go : using constanst for default values
Diffstat (limited to 'server.go')
-rw-r--r--server.go23
1 files changed, 15 insertions, 8 deletions
diff --git a/server.go b/server.go
index 0358cea..59d725b 100644
--- a/server.go
+++ b/server.go
@@ -1,30 +1,37 @@
package main
import (
+ "log"
+ "os"
+
"github.com/joho/godotenv"
"github.com/justsaumit/go-fis-api/handlers"
"github.com/labstack/echo/v4"
- "log"
- "os"
+)
+
+const (
+ defaultPort = "3000"
+ defaultDomain = "localhost"
+ defaultAPIEndpointURL = "http://localhost:3000"
)
func main() {
err := godotenv.Load() // Load .env file
if err != nil {
- log.Fatal("Error loading .env file")
+ log.Fatal("Error loading .env file", err)
}
port := os.Getenv("PORT")
if port == "" {
- port = "3000" // default port if not set
+ port = defaultPort
}
- domain := os.Getenv("DOMAIN")
+ domain, apiEndpointUrl := os.Getenv("DOMAIN")
api_endpoint_url := os.Getenv("API_ENDPOINT_URL")
if domain == "" || api_endpoint_url == "" {
- log.Println("Warning: DOMAIN and API_ENDPOINT_URL environment variable not set. Using localhost as default.")
- domain = "localhost"
- api_endpoint_url = "http://localhost:3000"
+ log.Println("Warning: DOMAIN and API_ENDPOINT_URL environment variable not set. Using defaults")
+ domain = defaultDomain
+ api_endpoint_url = defaultAPIEndpointURL
}
certPath := "/etc/letsencrypt/live/" + domain + "/fullchain.pem"