feat: set dev-mode into config

This commit is contained in:
Muyao CHEN 2024-10-02 23:12:35 +02:00
parent d7eba0a5d6
commit 792ee4ebe0
3 changed files with 10 additions and 2 deletions

View File

@ -20,6 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
dev-mode: true
addr: :8080
db:
@ -40,7 +42,6 @@ db:
log:
level: debug
development: true
disalbe-caller: false
disable-stacktrace: false
# console or json

View File

@ -75,7 +75,7 @@ func initConfig() {
func logOptions() *log.Options {
return &log.Options{
Level: viper.GetString("log.level"),
Development: viper.GetBool("log.development"),
Development: viper.GetBool("dev-mode"),
DisableCaller: viper.GetBool("log.disable-caller"),
DisableStacktrace: viper.GetBool("log.disable-stacktrace"),
Format: viper.GetString("log.format"),

View File

@ -102,6 +102,13 @@ func run() error {
log.InfoLog(string(settings))
log.InfoLog(viper.GetString("db.username"))
isDev := viper.GetBool("dev-mode")
if isDev {
gin.SetMode(gin.DebugMode)
} else {
gin.SetMode(gin.ReleaseMode)
}
r := gin.Default()
r.GET("/", func(ctx *gin.Context) {