-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
83 lines (70 loc) · 2.04 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
80
81
82
83
/*
* ReGraphQL - Proxy
* This is the proxy service of project ReGraphQL
*
* Contact: ezequiel.aceto+regraphql@gmail.com
*/
package main
import (
"flag"
"github.com/eaceto/ReGraphQL/app"
"github.com/eaceto/ReGraphQL/helpers"
serviceAPI "github.com/eaceto/ReGraphQL/services"
"github.com/gorilla/mux"
"github.com/spf13/pflag"
"github.com/spf13/viper"
"k8s.io/klog/v2"
"net/http"
"os"
"os/signal"
"syscall"
)
/*
* ReGraphQL
* A simple (yet effective) REST / HTTP to GraphQL router
*
* API version: 0.0.1
* Contact: ezequiel.aceto+regraphql@gmail.com
*/
func main() {
klog.InitFlags(nil) // initializing the flags
flag.Parse()
defer klog.Flush()
flag.String(app.ServerHostKey, app.ServerHostDefaultValue, "Server host")
flag.Int(app.ServerPortKey, app.ServerPortDefaultValue, "Server port")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
err := viper.BindPFlags(pflag.CommandLine)
if err != nil {
klog.Fatal(err)
}
router := mux.NewRouter()
application, err := app.NewApplication(router)
if err != nil {
klog.Fatal(err)
}
serviceAPI.AddServiceEndpoints(application, router)
if application.Configuration.DebugEnabled {
helpers.LogEndpoints(router)
}
srv := &http.Server{
Handler: router,
Addr: application.Configuration.ServerAddr,
ReadTimeout: application.Configuration.ServerReadTimeout,
WriteTimeout: application.Configuration.ServerWriteTimeout,
}
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go func() {
klog.InfoS("Server status", "status", "starting")
if application.Configuration.DebugEnabled {
klog.InfoS("Server props", "addr", application.Configuration.ServerAddr, "readTimeout", application.Configuration.ServerReadTimeout, "writeTimeout", application.Configuration.ServerWriteTimeout)
}
if err := srv.ListenAndServe(); err != http.ErrServerClosed {
klog.InfoS("Server status", "status", "error")
klog.Fatalf("ListenAndServe(): %v", err)
}
}()
<-done
klog.InfoS("Server status", "status", "stopped")
}