-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (56 loc) · 1.46 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
package main
import (
"flag"
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
"os"
)
const VERSION = `0.3.1`
var (
ErrorLog = log.New(os.Stderr, `error#`, log.Lshortfile)
DebugLog = log.New(os.Stdout, `debug#`, log.Lshortfile)
PrometheusErrors = prometheus.NewCounterVec(prometheus.CounterOpts{Name: `errors`,
Help: `Errors counter`}, []string{`action`, `get`, `repost`})
)
func helpText() {
fmt.Println(`# https://github.com/vvampirius/get-and-repost`)
flag.PrintDefaults()
}
func Pong(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `PONG`)
}
func main() {
help := flag.Bool("h", false, "print this help")
ver := flag.Bool("v", false, "Show version")
configFilePath := flag.String("c", "config.yml", "Path to YAML config")
flag.Parse()
if *help {
helpText()
os.Exit(0)
}
if *ver {
fmt.Println(VERSION)
os.Exit(0)
}
fmt.Printf("Starting version %s...\n", VERSION)
if err := prometheus.Register(PrometheusErrors); err != nil {
ErrorLog.Println(err.Error())
os.Exit(1)
}
configFile, err := NewConfigFile(*configFilePath)
if err != nil {
os.Exit(1)
}
if _, err = NewCore(configFile); err != nil {
os.Exit(1)
}
server := http.Server{Addr: configFile.Config.Listen}
http.HandleFunc(`/ping`, Pong)
http.Handle("/metrics", promhttp.Handler())
if err := server.ListenAndServe(); err != nil {
ErrorLog.Fatalln(err.Error())
}
}