This repository has been archived by the owner on Aug 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot.go
94 lines (79 loc) · 2 KB
/
robot.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
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2019 Silverbackhq. All rights reserved.
// Use of this source code is governed by the BSD 3-Clause
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"github.com/gin-gonic/gin"
"github.com/silverbackhq/svb-robot/internal/app/cmd"
"github.com/silverbackhq/svb-robot/internal/app/controller"
"github.com/silverbackhq/svb-robot/internal/app/middleware"
"github.com/silverbackhq/svb-robot/internal/app/pkg/utils"
"github.com/spf13/viper"
"io"
"net/http"
"os"
"strconv"
)
func main() {
var exec string
var configFile string
dir, err := os.Getwd()
if err != nil {
panic(fmt.Sprintf(
"Error while loading working directory: %s",
err.Error(),
))
}
os.Setenv("BasePath", dir)
flag.StringVar(&exec, "exec", "", "exec")
flag.StringVar(&configFile, "config", "config.prod.yml", "config")
flag.Parse()
viper.SetConfigFile(configFile)
err = viper.ReadInConfig()
if err != nil {
panic(fmt.Sprintf(
"Error while loading config file [%s]: %s",
configFile,
err.Error(),
))
}
if exec != "" {
switch exec {
case "health":
cmd.HealthStatus()
default:
utils.PrintCommands()
}
return
}
if viper.GetString("app.mode") == "prod" {
gin.SetMode(gin.ReleaseMode)
gin.DisableConsoleColor()
f, _ := os.Create(fmt.Sprintf("%s/gin.log", viper.GetString("log.path")))
gin.DefaultWriter = io.MultiWriter(f)
}
r := gin.Default()
r.Use(middleware.Correlation())
r.Use(middleware.Logger())
r.GET("/", controller.Index)
r.GET("/_healthcheck", controller.HealthCheck)
r.GET("/login", controller.Login)
r.GET("/auth", controller.Auth)
r.POST("/listen", controller.Listen)
r.GET("/favicon.ico", func(c *gin.Context) {
c.String(http.StatusNoContent, "")
})
if viper.GetBool("app.tls.status") {
r.RunTLS(
fmt.Sprintf(":%s", strconv.Itoa(viper.GetInt("app.port"))),
viper.GetString("app.tls.pemPath"),
viper.GetString("app.tls.keyPath"),
)
} else {
r.Run(
fmt.Sprintf(":%s", strconv.Itoa(viper.GetInt("app.port"))),
)
}
}