Inital commit
This commit is contained in:
60
misc/config/config.go
Normal file
60
misc/config/config.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"path/filepath"
|
||||
|
||||
"git.1248.nz/1248/Otfe/misc/helpers"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
//Configuration struct
|
||||
type Configuration struct {
|
||||
DB database `toml:"database"`
|
||||
Session session
|
||||
}
|
||||
|
||||
// Database stuct
|
||||
type database struct {
|
||||
Host string
|
||||
Name string
|
||||
User string
|
||||
Password string
|
||||
}
|
||||
|
||||
type session struct {
|
||||
SecretKey string
|
||||
Sessionkey string
|
||||
Timeout int
|
||||
}
|
||||
|
||||
var config *Configuration
|
||||
|
||||
func init() {
|
||||
Get()
|
||||
}
|
||||
|
||||
// Get config info from toml config file
|
||||
func Get() *Configuration {
|
||||
if config == nil {
|
||||
_, err := toml.DecodeFile(getConfigFile(), &config)
|
||||
helpers.CheckError(err)
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
func getConfigFile() string {
|
||||
return filepath.Join(helpers.GetRootDir(), "config.toml")
|
||||
}
|
||||
|
||||
func GetSecretKey() []byte {
|
||||
config := Get()
|
||||
key, err := hex.DecodeString(config.Session.SecretKey)
|
||||
helpers.CheckError(err)
|
||||
return key
|
||||
}
|
||||
|
||||
func GetSessionKey() string {
|
||||
return Get().Session.Sessionkey
|
||||
}
|
7
misc/config/config_test.go
Normal file
7
misc/config/config_test.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package config
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGetConfigFile(t *testing.T) {
|
||||
t.Log(Get())
|
||||
}
|
Reference in New Issue
Block a user