api

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StatusSuccess             = Status{Code: CodeSuccess, Msg: "success"}
	StatusInvalidParams       = Status{Code: CodeErrorInvalidParams, Msg: "invalid params"}
	StatusDatabase            = Status{Code: CodeErrorDatabase, Msg: "database error"}
	StatusUserNotExist        = Status{Code: CodeErrorUserNotExist, Msg: "user not exist"}
	StatusPassword            = Status{Code: CodeErrorPassword, Msg: "password error"}
	StatusTokenExpired        = Status{Code: CodeErrorTokenExpired, Msg: "token expired"}
	StatusUnauthorized        = Status{Code: CodeUnauthorized, Msg: "unauthorized"}
	StatusForbidden           = Status{Code: CodeErrorForbidden, Msg: "forbidden"}
	StatusInternalServerError = Status{Code: CodeErrorInternalServerError, Msg: "internal server error"}
)

Functions

func Fail added in v0.6.4

func Fail(c *gin.Context, status Status)

func FailHttpCode added in v0.6.4

func FailHttpCode(c *gin.Context, code int, status Status)

func FailInternalError

func FailInternalError(c *gin.Context)

func FailWithMsg

func FailWithMsg(c *gin.Context, msg string)

func Ok

func Ok(c *gin.Context)

func OkWithData

func OkWithData(c *gin.Context, data any)

func OkWithMsg

func OkWithMsg(c *gin.Context, msg string)

Types

type KeysetPage added in v0.6.4

type KeysetPage struct {
	// How many items to return per page.
	Limit int `json:"limit" form:"limit" binding:"required,min=1,max=100"`
	// Field name to sort by (e.g., "created_at", "name").
	// Must be a field suitable for keyset pagination (indexed, relatively unique).
	SortBy string `json:"sortBy" form:"sortBy" binding:"required"`
	// default is ASC, if true, then DESC
	DESC bool `json:"desc" form:"desc"`
	// An opaque cursor indicating the last item from the previous page (for forward pagination).
	// The client should send the 'nextCursor' received from the previous response here.
	After any `json:"after" form:"after"`
	// An opaque cursor indicating the first item from the previous page (for backward pagination).
	// The client should send the 'previousCursor' received from the previous response here.
	Before any `json:"before" form:"before"`
}

type KeysetPaginatedData added in v0.6.4

type KeysetPaginatedData[T any] struct {
	List []T `json:"list"`
	// Opaque cursor to fetch the next page. Null if no next page.
	NextCursor *string `json:"nextCursor"`
	// Opaque cursor to fetch the previous page. Null if no previous page.
	PreviousCursor *string `json:"previousCursor"`
}

type PageInfo added in v0.6.4

type PageInfo struct {
	// To retrive all items, just set the page very large
	Page     int `json:"page" form:"page" binding:"required,min=1"`
	PageSize int `json:"pageSize" form:"pageSize" binding:"required,min=1,max=100"`
}

type PaginatedData added in v0.6.4

type PaginatedData[T any] struct {
	List     []T   `json:"list"`
	Total    int64 `json:"total"`
	Page     int   `json:"page"`
	PageSize int   `json:"pageSize"`
}

type Response added in v0.6.4

type Response struct {
	Status
	Data any `json:"data"`
}

type Status

type Status struct {
	Code StatusCode `json:"code"`
	Msg  string     `json:"msg"`
}

func (Status) Send

func (s Status) Send(c *gin.Context)

type StatusCode

type StatusCode int
const (
	CodeSuccess                  StatusCode = 1
	CodeError                    StatusCode = 0
	CodeErrorInvalidParams       StatusCode = 2001
	CodeErrorDatabase            StatusCode = 2002
	CodeErrorUserNotExist        StatusCode = 2003
	CodeErrorPassword            StatusCode = 2004
	CodeErrorTokenExpired        StatusCode = 2005
	CodeUnauthorized             StatusCode = 2006
	CodeErrorInternalServerError StatusCode = 2007
	CodeErrorForbidden           StatusCode = 2008
)

Jump to

Keyboard shortcuts

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