32 lines
1.2 KiB
Go
32 lines
1.2 KiB
Go
// This file is the handler package's single vocabulary for HTTP replies: the
|
|
// envelope helpers come from pkg/httpx and Claims from the auth middleware, so
|
|
// handlers name one package instead of two.
|
|
package handler
|
|
|
|
import (
|
|
"kra/internal/biz/system"
|
|
"kra/internal/server/httpx"
|
|
"kra/internal/server/middleware"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
const (
|
|
CodeSuccess = httpx.CodeSuccess
|
|
CodeError = httpx.CodeError
|
|
CodePasswordChangeRequired = middleware.CodePasswordChangeRequired
|
|
)
|
|
|
|
type Response = httpx.Response
|
|
type PageResult = httpx.PageResult
|
|
|
|
func Write(c *gin.Context, code int, data any, message string) { httpx.Write(c, code, data, message) }
|
|
func OK(c *gin.Context) { httpx.OK(c) }
|
|
func OKWithData(c *gin.Context, data any) { httpx.OKWithData(c, data) }
|
|
func Fail(c *gin.Context, message string) { httpx.Fail(c, message) }
|
|
func NoAuth(c *gin.Context, message string) { httpx.NoAuth(c, message) }
|
|
func SetTokenCookie(c *gin.Context, value string, maxAge int) {
|
|
httpx.SetCookie(c, "x-token", value, maxAge)
|
|
}
|
|
func Claims(c *gin.Context) *system.AuthClaims { return middleware.Claims(c) }
|