-
Notifications
You must be signed in to change notification settings - Fork 18
/
config.go
46 lines (38 loc) · 931 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package server
import (
"errors"
"fmt"
"github.com/labstack/gommon/log"
"github.com/m0t0k1ch1/metamask-login-sample/application"
)
var (
ErrUnknownLogLevel = errors.New("Unknown log level")
)
var (
logLevels = map[string]log.Lvl{
"DEBUG": log.DEBUG,
"INFO": log.INFO,
"WARN": log.WARN,
"ERROR": log.ERROR,
"OFF": log.OFF,
}
)
type Config struct {
Port int `json:"port"`
IndexFilePath string `json:"index_file_path"`
StaticDirPath string `json:"static_dir_path"`
LogLevel string `json:"log_level"`
App *application.Config `json:"app"`
}
func (conf *Config) Validate() error {
if _, ok := logLevels[conf.LogLevel]; !ok {
return ErrUnknownLogLevel
}
return nil
}
func (conf *Config) Address() string {
return fmt.Sprintf(":%d", conf.Port)
}
func (conf *Config) LogLvl() log.Lvl {
return logLevels[conf.LogLevel]
}