-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (41 loc) · 795 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
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() {
initDatabaseConnection()
port := os.Getenv("AD_SERVICE_PORT")
if port == "" {
port = "8080"
}
ttl := os.Getenv("AD_SERVICE_CACHE_TTL")
if ttl == "" {
ttl = "1"
}
ttlInt, err := strconv.Atoi(ttl)
if err != nil {
log.Fatalf("Failed to parse cache TTL: %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("/ad", createAdHandler)
v1.GET("/ad", listAdsHandler)
}
}
log.Printf("Server starting on :%s", port)
if err := router.Run(":" + port); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}