Documentation ¶
Index ¶
- Constants
- Variables
- func DelCache(token string) error
- func Error(ctx *gin.Context, err error)
- func ErrorSystem(ctx *gin.Context, err error)
- func FieldTraceId(ctx interface{}) zap.Field
- func GetCache(token string) string
- func GetLoginSession(token string) (*model.User, error)
- func Paginator(page, pageSize int, count int64) map[string]interface{}
- func ParseBody(ctx *gin.Context, header *proto.RequestHeader, request interface{}) error
- func RenderJson(ctx *gin.Context, data interface{})
- func ResetCache(token string, expiration time.Duration) bool
- func SetCache(token, session string, expiration time.Duration) bool
- func SetLoginSession(token string, data *model.User) error
- func SwapGinContext(ctx2 *context.Context, ctx *gin.Context)
- type AdminContext
- type AdminError
- type Request
- type Result
Constants ¶
View Source
const ( ViewAdminGroupName = "/admin" ApiAdminGroupName = "/cgi-bin/v1" )
View Source
const ( ViewUrlLogin = "/login" ViewUrlDashboard = "/dashboard" ViewUrlArticleList = "/article/list" ViewUrlArticleSave = "/article/save" ViewUrlUserList = "/user/list" ViewUrlUserSave = "/user/save" ViewUrlUserModifyPassword = "/user/modify-password" ViewUrlSitePreferences = "/site/preferences" )
界面url定义
View Source
const ( ApiUrlArticleList = "/Admin/GetArticleList" ApiUrlArticleSave = "/Admin/SaveArticle" ApiUrlArticleDelete = "/Admin/DeleteArticle" ApiUrlArticleGetById = "/Admin/GetArticleById" ApiUrlLogin = "/Admin/UserLogin" ApiUrlUserLogout = "/Admin/UserLogout" ApiUrlUserSave = "/Admin/UserSave" ApiUrlUserModifyPassword = "/Admin/UserModifyPassword" ApiUrlUserList = "/Admin/GetUserList" // 公共接口 ApiUrlCommonUploadAttach = "/Admin/UploadAttachment" )
接口url定义
View Source
const AdminContextName = "AdminContext"
将前端传过来的东西转换成后端的context.Context必要的
Variables ¶
View Source
var AuthWhitePrefixUrl = map[string]byte{
"/source": 0x0,
"/attachment": 0x0,
}
鉴权白名单前缀匹配
View Source
var AuthWhiteUrl = map[string]byte{ UrlMap["U10001"]: 0x0, UrlMap["U00005"]: 0x0, UrlMap["U00004"]: 0x0, }
鉴权白名单, 不需要鉴权的url
View Source
var ErrCodeString = map[proto.RetCode]string{ proto.RetCode_Success: "成功", proto.RetCode_ErrorParam: "参数错误", proto.RetCode_ErrorSystem: "系统错误", proto.RetCode_ErrorNotFound: "没有找到数据", proto.RetCode_ErrorSessionExpired: "登录过期或没有登录", proto.RetCode_ErrorOldPassword: "旧密码错误", proto.RetCode_ErrorPassword: "密码错误", proto.RetCode_ErrorEmailFormat: "邮箱格式错误", }
错误码对应的文字
View Source
var UrlMap = map[string]string{ "U10001": ViewAdminGroupName + ViewUrlLogin, "U10002": ViewAdminGroupName + ViewUrlDashboard, "U10003": ViewAdminGroupName + ViewUrlArticleList, "U10004": ViewAdminGroupName + ViewUrlArticleSave, "U10005": ViewAdminGroupName + ViewUrlUserList, "U10006": ViewAdminGroupName + ViewUrlUserSave, "U10008": ViewAdminGroupName + ViewUrlUserModifyPassword, "U10007": ViewAdminGroupName + ViewUrlSitePreferences, "U00004": ApiAdminGroupName + ApiUrlCommonUploadAttach, "U00005": ApiAdminGroupName + ApiUrlLogin, "U00011": ApiAdminGroupName + ApiUrlUserLogout, "U00006": ApiAdminGroupName + ApiUrlArticleList, "U00007": ApiAdminGroupName + ApiUrlArticleSave, "U00008": ApiAdminGroupName + ApiUrlArticleDelete, "U00010": ApiAdminGroupName + ApiUrlArticleGetById, "U00012": ApiAdminGroupName + ApiUrlUserList, "U00009": ApiAdminGroupName + ApiUrlUserSave, "U00013": ApiAdminGroupName + ApiUrlUserModifyPassword, }
Functions ¶
Types ¶
type AdminContext ¶
context通用存储结构
func GetAdminContext ¶
func GetAdminContext(ctx context.Context) *AdminContext
func GetAdminContextFromGin ¶
func GetAdminContextFromGin(ctx *gin.Context) *AdminContext
type AdminError ¶
type AdminError struct {
// contains filtered or unexported fields
}
自定义错误
func NewAdminError ¶
func NewAdminError(code proto.RetCode, message string) *AdminError
生成一个带code的错误
func (*AdminError) Code ¶
func (a *AdminError) Code() proto.RetCode
func (*AdminError) Error ¶
func (a *AdminError) Error() string
type Request ¶
type Request struct { Header *proto.RequestHeader `json:"header"` Data interface{} `json:"data"` }
JSON 请求通用格式
type Result ¶
type Result struct { Header *proto.ResponseHeader `json:"header"` Data interface{} `json:"data"` }
JSON 返回通用格式
Click to show internal directories.
Click to hide internal directories.