-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
46 lines (41 loc) · 1020 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
package main
import (
"time"
"github.com/gin-gonic/gin"
"github.com/patrickmn/go-cache"
log "github.com/sirupsen/logrus"
)
var (
// G default gin engine
G = gin.Default()
// Cache Global news cache
Cache *cache.Cache
// CacheKey references news items in the cache
CacheKey string
// DefaultExpiration expires cache after 8 hours
DefaultExpiration = 8 * time.Hour
// CleanupInterval purges expired items
CleanupInterval = 8 * time.Hour
// Version holds the semantic version of application to output
Version string
)
func init() {
// Create cache on startup
Cache = createCache(DefaultExpiration, CleanupInterval)
log.Info("Cache created")
}
func main() {
// Err placeholder
var err error
log.Infof("Version: %v", Version)
// Add prometheus middleware
promMiddleware(G)
// Start custom metrics counters
recordMetrics()
// Initialize paths and handlers in routes.go
routes(G)
// Handle the errrrrrrs
if err = G.Run(); err != nil {
log.WithError(err).Fatal("Couldn't start server")
}
}