package configs
|
|
|
|
import (
|
|
"io"
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
type GenericOption struct {
|
|
Version string
|
|
Tag string
|
|
Log_File string // Logging output filename
|
|
Log_Level string // Logging Level
|
|
ListenAddr string // Listen HTTP Addr
|
|
JWT_Secret string // HTTP JWT Secret
|
|
Pool uint
|
|
Max_Rows uint
|
|
Readonly bool
|
|
Deletable bool
|
|
Debug bool // DEBUG control
|
|
DB string // Database connection URL
|
|
Cache string // Cache connection URL
|
|
KV string // KV engine connection URL
|
|
MSub string // Message Subscribe URL
|
|
MPub string // Message Publish URL
|
|
}
|
|
|
|
//type PostgresOption struct {
|
|
// Host string
|
|
// Port uint
|
|
// Username string
|
|
// Password string
|
|
// Database string
|
|
// Schema string
|
|
//}
|
|
//
|
|
//type RedisOption struct {
|
|
// Host string
|
|
// Port uint
|
|
// Database int64
|
|
//}
|
|
|
|
//type MQOption struct {
|
|
// Addresses string /* Multiple Address separated by ','*/
|
|
// ConnType string /* HTTP or TCP */
|
|
// Prefix string /* Topic Prefix, eg: node1, topics names will be added node1.xxx */
|
|
// Channel string /* Channel Name */
|
|
//}
|
|
|
|
func CheckConfiguration(option interface{}, output io.Writer) {
|
|
var _print = func(s string) {
|
|
io.WriteString(output, s)
|
|
}
|
|
_print("Checking options ...\n")
|
|
if nil == option {
|
|
_print("Invalid configuration!!!\n")
|
|
return
|
|
}
|
|
_print("\n")
|
|
toml.NewEncoder(output).Encode(option)
|
|
_print("\n")
|
|
_print("Configration validated!\n")
|
|
}
|
|
|
|
func LoadConfiguration(filename string, option interface{}) (e error) {
|
|
_, e = toml.DecodeFile(filename, option)
|
|
return e
|
|
}
|