Debugging
This commit is contained in:
@@ -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
|
||||
// }
|
||||
|
@@ -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())
|
||||
// }
|
||||
|
Reference in New Issue
Block a user