forked from chengshiwen/influx-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (55 loc) · 1.58 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
package main
import (
"flag"
"fmt"
"github.com/chengshiwen/influx-proxy/backend"
"github.com/chengshiwen/influx-proxy/config"
"github.com/chengshiwen/influx-proxy/service"
"log"
"net/http"
"runtime"
"time"
)
var (
ConfigFile string
Version bool
GitCommit string
BuildTime string
)
func main() {
flag.StringVar(&ConfigFile, "config", "proxy.json", "proxy config file")
flag.BoolVar(&Version, "version", false, "proxy version")
flag.Parse()
if Version {
fmt.Printf("Version: %s\n", config.Version)
fmt.Printf("Git commit: %s\n", GitCommit)
fmt.Printf("Go version: %s\n", runtime.Version())
fmt.Printf("Build time: %s\n", BuildTime)
fmt.Printf("OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
return
}
proxy, err := backend.NewProxy(ConfigFile)
if err != nil {
fmt.Println("config source load failed:", err.Error())
return
}
hs := service.HttpService{Proxy: proxy}
mux := http.NewServeMux()
hs.Register(mux)
server := &http.Server{
Addr: proxy.ListenAddr,
Handler: mux,
IdleTimeout: config.IdleTimeout * time.Second,
}
if proxy.HTTPSEnabled {
log.Printf("https service start, listen on %s", server.Addr)
err = server.ListenAndServeTLS(proxy.HTTPSCert, proxy.HTTPSKey)
} else {
log.Printf("http service start, listen on %s", server.Addr)
err = server.ListenAndServe()
}
if err != nil {
log.Print(err)
return
}
}