Inital commit

This commit is contained in:
2022-02-24 01:07:09 +13:00
commit 8bc3cee328
55 changed files with 2292 additions and 0 deletions

60
misc/config/config.go Normal file
View 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
}

View File

@@ -0,0 +1,7 @@
package config
import "testing"
func TestGetConfigFile(t *testing.T) {
t.Log(Get())
}