From 9c2ad91230d72fe6d661450cc78300ea223ae2bc Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Mon, 19 Oct 2020 11:05:36 +0530 Subject: make it better --- vendor/github.com/gin-gonic/gin/mode.go | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 vendor/github.com/gin-gonic/gin/mode.go (limited to 'vendor/github.com/gin-gonic/gin/mode.go') diff --git a/vendor/github.com/gin-gonic/gin/mode.go b/vendor/github.com/gin-gonic/gin/mode.go new file mode 100644 index 0000000..15efaeb --- /dev/null +++ b/vendor/github.com/gin-gonic/gin/mode.go @@ -0,0 +1,61 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + +package gin + +import ( + "io" + "os" + + "github.com/gin-gonic/gin/binding" + "github.com/mattn/go-colorable" +) + +const ENV_GIN_MODE = "GIN_MODE" + +const ( + DebugMode string = "debug" + ReleaseMode string = "release" + TestMode string = "test" +) +const ( + debugCode = iota + releaseCode = iota + testCode = iota +) + +var DefaultWriter io.Writer = colorable.NewColorableStdout() +var ginMode int = debugCode +var modeName string = DebugMode + +func init() { + mode := os.Getenv(ENV_GIN_MODE) + if len(mode) == 0 { + SetMode(DebugMode) + } else { + SetMode(mode) + } +} + +func SetMode(value string) { + switch value { + case DebugMode: + ginMode = debugCode + case ReleaseMode: + ginMode = releaseCode + case TestMode: + ginMode = testCode + default: + panic("gin mode unknown: " + value) + } + modeName = value +} + +func DisableBindValidation() { + binding.Validator = nil +} + +func Mode() string { + return modeName +} -- cgit v1.2.3