41 lines
676 B
Go
41 lines
676 B
Go
package models
|
|
|
|
import (
|
|
"github.com/go-ini/ini"
|
|
"os"
|
|
)
|
|
|
|
// Config holds the config struct
|
|
var Config struct {
|
|
Database struct {
|
|
Host string
|
|
User string
|
|
Password string
|
|
Database string
|
|
}
|
|
|
|
JWTLoginSecret []byte
|
|
}
|
|
|
|
// SetConfig initianlises the config and publishes it for other functions to use
|
|
func SetConfig() error {
|
|
|
|
// File Checks
|
|
if _, err := os.Stat("config.ini"); os.IsNotExist(err) {
|
|
return err
|
|
}
|
|
|
|
cfg, err := ini.Load("config.ini")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Database
|
|
cfg.Section("Database").MapTo(Config.Database)
|
|
|
|
// JWT secret
|
|
Config.JWTLoginSecret = []byte(cfg.Section("General").Key("JWTSecret").String())
|
|
|
|
return nil
|
|
}
|