-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
58 lines (46 loc) · 1.28 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"log"
"os"
"github.com/joho/godotenv"
"github.com/justsaumit/go-fis-api/handlers"
"github.com/labstack/echo/v4"
)
const (
defaultPort = "3000"
)
func main() {
godotenv.Load()
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
log.Println("No port specified; running on the default port 3000")
}
e := echo.New()
e.GET("/", handlers.HealthCheck)
e.POST("/upload", handlers.AddHash)
e.POST("/verify", handlers.VerifyHash)
environment := os.Getenv("ENVIRONMENT")
switch environment {
case "production":
startProductionServer(e, port)
case "development":
startDevelopmentServer(e, port)
default:
log.Printf("Unknown environment '%s', running without TLS encryption\n", environment)
e.Logger.Fatal(e.Start(":" + port))
}
}
func startProductionServer(e *echo.Echo, port string) {
certPath := os.Getenv("CERTPATH")
keyPath := os.Getenv("KEYPATH")
if certPath == "" || keyPath == "" {
log.Fatal("Certificate or key path not provided for production environment")
}
log.Printf("Starting production server on port %s\n", port)
e.Logger.Fatal(e.StartTLS(":"+port, certPath, keyPath))
}
func startDevelopmentServer(e *echo.Echo, port string) {
log.Printf("Starting development server on port %s\n", port)
e.Logger.Fatal(e.Start(":" + port))
}