-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (41 loc) · 848 Bytes
/
main.go
File metadata and controls
50 lines (41 loc) · 848 Bytes
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
package main
import (
"log"
"os"
"strconv"
"time"
"github.com/gin-gonic/gin"
)
var (
cache = Cache{}
)
func main() {
initialDatabaseConnection()
port := os.Getenv("SERVICE_PORT")
if port == "" {
port = "8080"
}
ttl := os.Getenv("CACHE_TTL")
if ttl == "" {
ttl = "1"
}
ttlInt, err := strconv.Atoi(ttl)
if err != nil {
log.Fatalf("Failed to convert CACHE_TTL to int: %v", err)
}
go cache.Updater(time.Second * time.Duration(ttlInt))
router := gin.New()
router.Use(gin.Recovery())
api := router.Group("/api")
{
v1 := api.Group("/v1")
{
v1.POST("/ads", createAdHandler)
v1.GET("/ads", getAdsHandler)
}
}
log.Printf("Starting server on port %s", port)
if err := router.Run(":" + port); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}