|
@ -0,0 +1,56 @@ |
|
|
|
|
|
package configs |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
|
"io" |
|
|
|
|
|
"github.com/BurntSushi/toml" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type GenericOption struct { |
|
|
|
|
|
Version string |
|
|
|
|
|
Tag string |
|
|
|
|
|
Log_File string |
|
|
|
|
|
Log_Level string |
|
|
|
|
|
ListenAddr string |
|
|
|
|
|
Debug bool |
|
|
|
|
|
Cache bool |
|
|
|
|
|
Pool uint |
|
|
|
|
|
Max_Rows uint |
|
|
|
|
|
Readonly bool |
|
|
|
|
|
Deletable bool |
|
|
|
|
|
JWT_Secret string |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type PostgresOption struct { |
|
|
|
|
|
Host string |
|
|
|
|
|
Port uint |
|
|
|
|
|
Username string |
|
|
|
|
|
Password string |
|
|
|
|
|
Database string |
|
|
|
|
|
Schema string |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type RedisOption struct { |
|
|
|
|
|
Host string |
|
|
|
|
|
Port uint |
|
|
|
|
|
Database int64 |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
} |