package model import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" ) type Config struct { Srv struct { HostName string `yaml:"hostname"` Port string `yaml:"port"` Mode string `yaml:"mode"` LogLevel int `yaml:"loglevel"` LogPath string `yaml:"logpath"` MaxSizeFile int64 `yaml:"maxsizefile"` } `yaml:"srv"` } // NewConfig Set Default func NewConfig() *Config { var cnf Config cnf.Srv.HostName = "example.com" cnf.Srv.Port = "8080" cnf.Srv.Mode = gin.DebugMode cnf.Srv.LogLevel = int(logrus.DebugLevel) cnf.Srv.LogPath = "./log" cnf.Srv.MaxSizeFile = 2 //2 Mb return &cnf } func ValidLogLevel(cnf *Config) logrus.Level { switch cnf.Srv.LogLevel { case int(logrus.PanicLevel): return logrus.PanicLevel //PanicLevel = 0 case int(logrus.FatalLevel): return logrus.FatalLevel //FatalLevel = 1 case int(logrus.ErrorLevel): return logrus.ErrorLevel //ErrorLevel = 2 case int(logrus.WarnLevel): return logrus.WarnLevel //WarnLevel = 3 case int(logrus.InfoLevel): return logrus.InfoLevel //InfoLevel = 4 case int(logrus.DebugLevel): return logrus.DebugLevel //DebugLevel = 5 case int(logrus.TraceLevel): return logrus.TraceLevel //TraceLevel = 6 } return logrus.DebugLevel }