Debugging

This commit is contained in:
2022-03-13 07:06:39 +13:00
parent 8bc3cee328
commit dc8de8b4b9
31 changed files with 952 additions and 1040 deletions

View File

@@ -1,60 +1,60 @@
package config
// package config
import (
"encoding/hex"
"path/filepath"
// import (
// "encoding/hex"
// "path/filepath"
"git.1248.nz/1248/Otfe/misc/helpers"
// "git.technical.kiwi/go/otfe/misc/helpers"
"github.com/BurntSushi/toml"
)
// "github.com/BurntSushi/toml"
// )
//Configuration struct
type Configuration struct {
DB database `toml:"database"`
Session session
}
// //Configuration struct
// type Configuration struct {
// DB database `toml:"database"`
// Session session
// }
// Database stuct
type database struct {
Host string
Name string
User string
Password string
}
// // Database stuct
// type database struct {
// Host string
// Name string
// User string
// Password string
// }
type session struct {
SecretKey string
Sessionkey string
Timeout int
}
// type session struct {
// SecretKey string
// Sessionkey string
// Timeout int
// }
var config *Configuration
// var config *Configuration
func init() {
Get()
}
// 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
}
// // 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 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 GetSecretKey() []byte {
// config := Get()
// key, err := hex.DecodeString(config.Session.SecretKey)
// helpers.CheckError(err)
// return key
// }
func GetSessionKey() string {
return Get().Session.Sessionkey
}
// func GetSessionKey() string {
// return Get().Session.Sessionkey
// }

View File

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