Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adds API to switch the gin's mode - Log listening port - Log routes
- Loading branch information
1 parent
312e032
commit 809eee8
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package gin | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
const GIN_MODE = "GIN_MODE" | ||
|
||
const ( | ||
DebugMode string = "debug" | ||
ReleaseMode string = "release" | ||
) | ||
const ( | ||
debugCode = iota | ||
releaseCode = iota | ||
) | ||
|
||
var gin_mode int = debugCode | ||
|
||
func SetMode(value string) { | ||
switch value { | ||
case DebugMode: | ||
gin_mode = debugCode | ||
case ReleaseMode: | ||
gin_mode = releaseCode | ||
default: | ||
panic("gin mode unknown, the allowed modes are: " + DebugMode + " and " + ReleaseMode) | ||
} | ||
} | ||
|
||
func init() { | ||
value := os.Getenv(GIN_MODE) | ||
if len(value) == 0 { | ||
SetMode(DebugMode) | ||
} else { | ||
SetMode(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I think it's better to have a debugging API, as in: