Moved interface setting to config

This commit is contained in:
konrad 2017-11-16 13:04:45 +01:00 committed by kolaente
parent c98c593307
commit df0ad4adeb
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,7 @@
[General] [General]
JWTSecret = blablaGEHEMIN§)!§ JWTSecret = blablaGEHEMIN§)!§
; The interface on which to run the webserver
Interface = :8082
[Database] [Database]
User = root User = root

View File

@ -193,6 +193,7 @@ export default {
}) })
}, },
getStatusByID: function (id) { getStatusByID: function (id) {
// TODO: is there a better way to do this?
for (const i in this.allStatus) { for (const i in this.allStatus) {
if (this.allStatus[i].ID === id) { if (this.allStatus[i].ID === id) {
return this.allStatus[i].Name return this.allStatus[i].Name

View File

@ -30,5 +30,5 @@ func main() {
// Start the webserver // Start the webserver
e := routes.NewEcho() e := routes.NewEcho()
routes.RegisterRoutes(e) routes.RegisterRoutes(e)
e.Start(":8082") e.Start(models.Config.Interface)
} }

View File

@ -15,6 +15,7 @@ type ConfigStruct struct {
} }
JWTLoginSecret []byte JWTLoginSecret []byte
Interface string
FirstUser User `ini:"User"` FirstUser User `ini:"User"`
} }
@ -30,16 +31,24 @@ func SetConfig() error {
return err return err
} }
// Load the config
cfg, err := ini.Load("config.ini") cfg, err := ini.Load("config.ini")
if err != nil { if err != nil {
return err return err
} }
// Map the config to our struct
err = cfg.MapTo(Config) err = cfg.MapTo(Config)
if err != nil { if err != nil {
return err return err
} }
// Set default value for interface to listen on
Config.Interface = cfg.Section("General").Key("Interface").String()
if Config.Interface == "" {
Config.Interface = ":8080"
}
// JWT secret // JWT secret
Config.JWTLoginSecret = []byte(cfg.Section("General").Key("JWTSecret").String()) Config.JWTLoginSecret = []byte(cfg.Section("General").Key("JWTSecret").String())