common

package
v0.0.0-...-25ebaee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

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 ErrorHandling

func ErrorHandling() gin.HandlerFunc

ErrorHandling 错误处理中间件

func FuncHandler

func FuncHandler(c *gin.Context, i interface{}, judge interface{}, option ...interface{}) bool

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 GetLogFile() *os.File

func GetMySQL

func GetMySQL() *gorm.DB

func InitLogger

func InitLogger()

func InitMySQL

func InitMySQL() *gorm.DB

func InitSentry

func InitSentry()

func MaintenanceHandling

func MaintenanceHandling() gin.HandlerFunc

func SetConfig

func SetConfig() error

func WatchConfig

func WatchConfig() error

Types

type Database

type Database struct {
	*gorm.DB
}

type GeneralReturn

type GeneralReturn struct {
	CustomMessage string
	HTTPStatus    int
	AppErrJSON    appErrJSON
}

GeneralReturn 通用码

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL