run the server using the configuration
This commit is contained in:
parent
d1cefa4131
commit
9339cdbd93
29
main.go
29
main.go
|
@ -25,51 +25,40 @@ func main() {
|
|||
e := echo.New()
|
||||
e.HideBanner = true
|
||||
|
||||
RI3_USERNAME := os.Getenv("RI3_USERNAME")
|
||||
RI3_PASSWORD := os.Getenv("RI3_PASSWORD")
|
||||
RI3_BIND := os.Getenv("RI3_BIND")
|
||||
|
||||
if RI3_BIND == "" {
|
||||
RI3_BIND = "0.0.0.0:4000"
|
||||
}
|
||||
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Errorf("Configuration requried")
|
||||
fmt.Errorf("Configuration required!")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
value, err := createConfigFromFile(os.Args[1])
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Configuration error:")
|
||||
fmt.Printf("%+v\n", err)
|
||||
fmt.Errorf("Configuration error")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
config = value
|
||||
|
||||
fmt.Printf("%+v\n", config)
|
||||
|
||||
assetHandler := http.FileServer(rice.MustFindBox("static").HTTPBox())
|
||||
|
||||
e.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
|
||||
if RI3_USERNAME == "" && RI3_PASSWORD == "" {
|
||||
if config.Server.Auth.Username == "" && config.Server.Auth.Password == "" {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
isValidUsername := subtle.ConstantTimeCompare([]byte(username), []byte(RI3_USERNAME)) == 1
|
||||
isValidPassword := subtle.ConstantTimeCompare([]byte(password), []byte(RI3_PASSWORD)) == 1
|
||||
isValidUsername := subtle.ConstantTimeCompare([]byte(username), []byte(config.Server.Auth.Username)) == 1
|
||||
isValidPassword := subtle.ConstantTimeCompare([]byte(password), []byte(config.Server.Auth.Password)) == 1
|
||||
|
||||
if isValidUsername && isValidPassword {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}))
|
||||
|
||||
e.GET("/", echo.WrapHandler(assetHandler))
|
||||
assetHandler := http.FileServer(rice.MustFindBox("static").HTTPBox())
|
||||
|
||||
e.GET("/static/*", echo.WrapHandler(http.StripPrefix("/static/", assetHandler)))
|
||||
e.GET("/", homeController)
|
||||
e.GET("/ws", wsController)
|
||||
|
||||
e.Logger.Fatal(e.Start(RI3_BIND))
|
||||
e.Logger.Fatal(e.Start(config.Server.Listen))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue