handlers

package
v1.21.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageOK           = "ok"
	MessageNotFound     = "not found"
	MessageError        = "err"
	MessageForbidden    = "forbidden"
	MessageUnauthorized = "unauthorized"
)
View Source
const (
	ASC  = "ASC"
	DESC = "DESC"
)

Variables

View Source
var (
	NoopPageFilterFunc = func(i int) bool { return true }
	NoopPageSortFunc   = func(i, j int) bool { return false }
)
View Source
var (
	QueryPageNum  = restful.QueryParameter("page", "page number")
	QueryPageSize = restful.QueryParameter("size", "page size")
	QuerySearch   = restful.QueryParameter("search", "search condition")
	QueryOrder    = restful.QueryParameter("order", "order")
)
View Source
var NewPageFromContext = pagination.NewPageDataFromContext

Functions

func BadRequest

func BadRequest(resp *restful.Response, err error)

func BindData

func BindData(req *restful.Request, data interface{}) error

func BindQuery

func BindQuery(req *restful.Request, data interface{}) error

func CommonOptions

func CommonOptions(req *restful.Request) []client.Option

func Created

func Created(resp *restful.Response, data interface{})

func Forbidden

func Forbidden(resp *restful.Response, data interface{})

func IsNotFound

func IsNotFound(err error) bool

func ListCommonQuery

func ListCommonQuery(rb *restful.RouteBuilder) *restful.RouteBuilder

func NoContent

func NoContent(resp *restful.Response, data interface{})

func NotFound

func NotFound(resp *restful.Response, data interface{})

func NotFoundOrBadRequest

func NotFoundOrBadRequest(resp *restful.Response, err error)

func OK

func OK(resp *restful.Response, data interface{})

func OrderOption

func OrderOption(req *restful.Request) []client.Option

TODO: handler order priority, "order by id, age" vs "order by age, id"

func PageSizeOption

func PageSizeOption(req *restful.Request) client.Option

func ParseError

func ParseError(err error) interface{}

func PreloadOption

func PreloadOption(req *restful.Request) client.Option

func ScopeBelongM2M

func ScopeBelongM2M(ownerModel, selfModel, viaModel interface{}, cond *Cond, refSelfField, refOwnerField string) func(tx *gorm.DB) *gorm.DB

func ScopeBelongViaField

func ScopeBelongViaField(model, selfmodel interface{}, cond *Cond, relfield string) func(tx *gorm.DB) *gorm.DB

func ScopeCondition

func ScopeCondition(conds []*Cond, model interface{}) func(tx *gorm.DB) *gorm.DB

func ScopeFields

func ScopeFields(model interface{}, fields []string) func(tx *gorm.DB) *gorm.DB

func ScopeOmitAssociations

func ScopeOmitAssociations(tx *gorm.DB) *gorm.DB

func ScopeOrder

func ScopeOrder(req *restful.Request, valid []string) func(tx *gorm.DB) *gorm.DB

func ScopePageSize

func ScopePageSize(req *restful.Request) func(tx *gorm.DB) *gorm.DB

func ScopePreload

func ScopePreload(req *restful.Request, validPreloads []string) func(tx *gorm.DB) *gorm.DB

func ScopeSearch

func ScopeSearch(req *restful.Request, model interface{}, fields []string) func(tx *gorm.DB) *gorm.DB

func ScopeTable

func ScopeTable(model interface{}) func(tx *gorm.DB) *gorm.DB

func SearchOption

func SearchOption(req *restful.Request) client.Option

func ServiceUnavailable

func ServiceUnavailable(resp *restful.Response, err error)

func Unauthorized

func Unauthorized(resp *restful.Response, data interface{})

func WhereOptions

func WhereOptions(req *restful.Request, queryWhiteList []string) []client.Option

Types

type Cond

type Cond struct {
	Field string
	Op    ConditionOperator
	Value interface{}
}

func Where

func Where(field string, op ConditionOperator, value interface{}) *Cond

func WhereEqual

func WhereEqual(field string, value interface{}) *Cond

func WhereNameEqual

func WhereNameEqual(value interface{}) *Cond

func (*Cond) AsQuery

func (cond *Cond) AsQuery() (string, interface{})

type ConditionOperator

type ConditionOperator string
var Eq, Gt, Lt, Neq, Gte, Lte, In, Like ConditionOperator = "=", ">", "<", "<>", ">=", "<=", "in", "like"

type ListBase

type ListBase struct {
	Total       int64 `json:"total"`
	CurrentPage int64 `json:"page"`
	CurrentSize int64 `json:"size"`
}

type PageData

type PageData struct {
	Total       int64       `json:"total"`
	List        interface{} `json:"list"`
	CurrentPage int         `json:"page"`
	CurrentSize int         `json:"size"`
}

func NewPageData

func NewPageData(list interface{}, page, size int, filterfn PageFilterFunc, sortfn PageSortFunc) PageData

func NewPageDataFromContext

func NewPageDataFromContext(req *restful.Request, fulllist interface{}, pick PageFilterFunc, sortfn PageSortFunc) PageData

func Page

func Page(db *gorm.DB, total int64, data interface{}) *PageData

type PageFilterFunc

type PageFilterFunc func(i int) bool

type PageSortFunc

type PageSortFunc func(i, j int) bool

type RelationCondition

type RelationCondition struct {
	Key   string
	Value interface{}
	Table string
}

type RespBase

type RespBase struct {
	Message   string      `json:"message"`
	ErrorData interface{} `json:"err"`
}

type Response

type Response struct {
	Message   string      `json:"message"`
	Data      interface{} `json:"data"`
	ErrorData interface{} `json:"err,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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