utils

package
v0.0.0-...-2a4dbc0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommentFilter *sensitive.Filter
View Source
var EmojiJson []dto.EmojiJson
View Source
var ErrTokenNotProvided = fmt.Errorf("token not provided")
View Source
var ErrTokenUserNotFound = fmt.Errorf("user not found")

Functions

func CheckIsAdminReq

func CheckIsAdminReq(c *fiber.Ctx) bool

func GetTokenByReq

func GetTokenByReq(c *fiber.Ctx) string

func GetUserByReq

func GetUserByReq(c *fiber.Ctx) (*model.User, error)

func InitCommentFilter

func InitCommentFilter()

func InitEmoji

func InitEmoji()

InitEmoji 初始化Emoji

func LoginGetUserToken

func LoginGetUserToken(user model.User, key string, ttl int) (string, error)

func ParamsDecode

func ParamsDecode(c *fiber.Ctx, destParams interface{}) (isContinue bool, resp error)

func SendError

func SendError(c *fiber.Ctx, code int, message string) error

SendError sends an error JSON response with a specified code and message

func SendResponse

func SendResponse(c *fiber.Ctx, code int, message string, data interface{}) error

SendResponse sends a JSON response to the client

func SendSuccess

func SendSuccess(c *fiber.Ctx, data interface{}) error

SendSuccess sends a successful JSON response with a default code of 200

func ValidateEmail

func ValidateEmail(email string) bool

func ValidateRequired

func ValidateRequired(c *fiber.Ctx, destParams interface{}) (isContinue bool, resp error)

func ValidateURL

func ValidateURL(url string) bool

Types

type JwtCustomClaims

type JwtCustomClaims struct {
	UserID uint `json:"user_id"`
	jwt.StandardClaims
}

JwtCustomClaims are custom claims extending default ones. See https://github.com/golang-jwt/jwt for more examples

func GetJwtDataByReq

func GetJwtDataByReq(c *fiber.Ctx) (JwtCustomClaims, error)

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

Response is the standard response structure

func NewResponse

func NewResponse(code int, message string, data interface{}) *Response

NewResponse creates a new response object

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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