github.com/wangyougui/gf/v2@v2.6.5/internal/errors/errors.go (about) 1 // Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 // Package errors provides functionalities to manipulate errors for internal usage purpose. 8 package errors 9 10 import ( 11 "github.com/wangyougui/gf/v2/internal/command" 12 ) 13 14 // StackMode is the mode that printing stack information in StackModeBrief or StackModeDetail mode. 15 type StackMode string 16 17 const ( 18 // commandEnvKeyForBrief is the command environment name for switch key for brief error stack. 19 // Deprecated: use commandEnvKeyForStackMode instead. 20 commandEnvKeyForBrief = "gf.gerror.brief" 21 22 // commandEnvKeyForStackMode is the command environment name for switch key for brief error stack. 23 commandEnvKeyForStackMode = "gf.gerror.stack.mode" 24 ) 25 26 const ( 27 // StackModeBrief specifies all error stacks printing no framework error stacks. 28 StackModeBrief StackMode = "brief" 29 30 // StackModeDetail specifies all error stacks printing detailed error stacks including framework stacks. 31 StackModeDetail StackMode = "detail" 32 ) 33 34 var ( 35 // stackModeConfigured is the configured error stack mode variable. 36 // It is brief stack mode in default. 37 stackModeConfigured = StackModeBrief 38 ) 39 40 func init() { 41 // Deprecated. 42 briefSetting := command.GetOptWithEnv(commandEnvKeyForBrief) 43 if briefSetting == "1" || briefSetting == "true" { 44 stackModeConfigured = StackModeBrief 45 } 46 47 // The error stack mode is configured using command line arguments or environments. 48 stackModeSetting := command.GetOptWithEnv(commandEnvKeyForStackMode) 49 if stackModeSetting != "" { 50 stackModeSettingMode := StackMode(stackModeSetting) 51 switch stackModeSettingMode { 52 case StackModeBrief, StackModeDetail: 53 stackModeConfigured = stackModeSettingMode 54 } 55 } 56 } 57 58 // IsStackModeBrief returns whether current error stack mode is in brief mode. 59 func IsStackModeBrief() bool { 60 return stackModeConfigured == StackModeBrief 61 }