Documentation ¶
Index ¶
- Constants
- Variables
- func DefaultConfig() error
- func ErrorHandling() gin.HandlerFunc
- func FuncHandler(c *gin.Context, i interface{}, judge interface{}, option ...interface{}) bool
- func GetLogFile() *os.File
- func GetMySQL() *gorm.DB
- func InitLogger()
- func InitMySQL() *gorm.DB
- func InitSentry()
- func MaintenanceHandling() gin.HandlerFunc
- func SetConfig() error
- func WatchConfig() error
- type Database
- type GeneralReturn
Constants ¶
View Source
const ( CSRF_SESSION_NAME string = "example-session" CSRF_SECRET string = "example-secret" )
View Source
const VERSION = "1.0.0-alpha"
application version
Variables ¶
View Source
var CORS_ALLOW_DEBUG_ORIGINS = []string{
"http://*",
"https://*",
}
View Source
var CORS_ALLOW_HEADERS = []string{
"Origin",
"Content-Length",
"Content-Type",
"Token",
"X-CSRF-TOKEN",
"withCredentials",
}
View Source
var CORS_ALLOW_METHODS = []string{
"GET",
"POST",
"PUT",
"PATCH",
"DELETE",
"HEAD",
}
View Source
var CORS_ALLOW_ORIGINS = []string{
"https://example.a2os.club",
"https://test.example.a2os.club",
"http://example.a2os.club",
"http://test.example.a2os.club",
}
Cross-sites resource sharing settings
View Source
var CORS_EXPOSE_HEADERS = []string{
"X-CSRF-TOKEN",
"Token",
}
View Source
var CSRF_COOKIE_SECRET = []byte("csrf-secret")
View Source
var Errors = map[int]string{
0: "OK",
10001: "System error",
10002: "Service unavailable",
10003: "Parameter error",
10004: "Parameter value invalid",
10005: "Missing required parameter",
10006: "Resource unavailable",
10007: "CSRF token mismatch",
10008: "This service is undergoing maintenance",
20000: "Application error",
}
Errors 错误码
View Source
var (
MySQL *gorm.DB
)
Functions ¶
func DefaultConfig ¶
func DefaultConfig() error
func FuncHandler ¶
FuncHandler 统一错误处理 i 传入error,bool,int judge 触发正确值 非error环境下有效 如果触发了错误 return True Example: 1. common.FuncHandler(c, c.BindJSON(&x), nil, http.StatusBadRequest, 20301)
== if(c.BindJSON(&x) != nil){ c.JSON(http.StatusBadRequest, gin.H{ "err_code": 20301, "message": common.Errors[20301], }) }
2. common.FuncHandler(c, c.BindJSON(&x), nil, http.StatusBadRequest, 20301,fmt.Sprintf("BindJson fail with %v",x))
== if(c.BindJSON(&x) != nil){ log.Println(fmt.Sprintf("BindJson fail with %v",x)) c.JSON(http.StatusBadRequest, gin.H{ "err_code": 20301, "message": common.Errors[20301], }) }
3. common.FuncHandler(c, isOdd(2), true, fmt.Sprintf("%d is even",2))
== if(isOdd(2) != true){ log.Println(fmt.Sprintf("%d is even",2)) }
func GetLogFile ¶
func InitLogger ¶
func InitLogger()
func InitSentry ¶
func InitSentry()
func MaintenanceHandling ¶
func MaintenanceHandling() gin.HandlerFunc
func WatchConfig ¶
func WatchConfig() error
Types ¶
type GeneralReturn ¶
GeneralReturn 通用码
Click to show internal directories.
Click to hide internal directories.