-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (41 loc) · 856 Bytes
/
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
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"log"
)
func runServer() {
if config.Release {
gin.SetMode(gin.ReleaseMode)
}
r := gin.Default()
if config.AllowCors {
r.Use(corsMiddleware())
}
if config.NoCacheHeaders {
r.Use(nocacheMiddleware)
}
// token creation
r.POST("/token", tokenHandler)
if config.AllowWebLogin {
r.LoadHTMLGlob("templates/*.html")
r.GET("/login", webFormHandler)
r.POST("/login", loginHandler)
r.POST("/logout", logoutHandler)
}
// authenticated proxy handler
path := fmt.Sprintf("%s/*path", config.ProxyPath)
r.Any(path, authMiddleware, proxyHandler)
// Run the server
err := r.Run(fmt.Sprintf(":%d", config.ServerPort))
if err != nil {
log.Fatal(err)
} // listens and serves on defined port
}
func main() {
parseFlags()
readConfig()
readEnv()
readUsers()
runServer()
}