sirius/internal/model/config.go

58 lines
1.2 KiB
Go
Raw Normal View History

2023-04-17 08:48:09 +03:00
package model
2023-04-17 05:00:34 +03:00
import (
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
2023-04-17 05:00:34 +03:00
)
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
}
2023-04-17 05:00:34 +03:00
return logrus.DebugLevel
2023-04-17 05:00:34 +03:00
}