-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (35 loc) · 951 Bytes
/
main.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
package main
import (
"log"
"os"
"github.com/joho/godotenv"
"github.com/gin-gonic/gin"
"glutara/router"
)
func init() {
// Load environment variables from
if err := godotenv.Load(); err != nil {
log.Fatal("Error loading .env file")
}
}
func main() {
// Initialize Gin router
r := gin.Default()
// Configure router to include routes and middlewares
router.ConfigureRouter(r)
// Start server
// Use `PORT` provided in environment or default to 8080
r.Run(envPortOr("8080"))
}
// PORT handling
// Returns PORT from environment if found, defaults to
// value in `port` parameter otherwise. The returned port
// is prefixed with a `:`, e.g. `":8080"`.
func envPortOr(port string) string {
// If `PORT` variable in environment exists, return it
if envPort := os.Getenv("PORT"); envPort != "" {
return ":" + envPort
}
// Otherwise, return the value of `port` variable from function argument
return ":" + port
}