forked from minotar/imgd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (65 loc) · 1.5 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"fmt"
"github.com/gorilla/mux"
"github.com/op/go-logging"
"net/http"
"os"
"runtime"
)
const (
DefaultSize = uint(180)
MaxSize = uint(300)
MinSize = uint(8)
SkinCache
Minutes uint = 60
Hours = 60 * Minutes
Days = 24 * Hours
TimeoutActualSkin = 2 * Days
TimeoutFailedFetch = 15 * Minutes
MinotarVersion = "2.7"
)
var (
config = &Configuration{}
cache Cache
stats *StatusCollector
signalHandler *SignalHandler
)
var log = logging.MustGetLogger("imgd")
var format = "[%{time:15:04:05.000000}] %{level:.4s} %{message}"
func setupConfig() {
err := config.load()
if err != nil {
fmt.Printf("Error loading config: %s\n", err)
return
}
}
func setupCache() {
cache = MakeCache(config.Server.Cache)
err := cache.setup()
if err != nil {
log.Critical("Unable to setup Cache. (" + fmt.Sprintf("%v", err) + ")")
os.Exit(1)
}
}
func setupLog(logBackend *logging.LogBackend) {
logging.SetBackend(logBackend)
logging.SetFormatter(logging.MustStringFormatter(format))
}
func startServer() {
r := Router{Mux: mux.NewRouter()}
r.Bind()
http.Handle("/", r.Mux)
err := http.ListenAndServe(config.Server.Address, nil)
log.Critical(err.Error())
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
logBackend := logging.NewLogBackend(os.Stdout, "", 0)
signalHandler = MakeSignalHandler()
stats = MakeStatsCollector()
setupLog(logBackend)
setupConfig()
setupCache()
startServer()
}