Documentation
¶
Index ¶
- Constants
- Variables
- func BadRequest(resp *restful.Response, err error)
- func BindData(req *restful.Request, data interface{}) error
- func BindQuery(req *restful.Request, data interface{}) error
- func CommonOptions(req *restful.Request) []client.Option
- func Created(resp *restful.Response, data interface{})
- func Forbidden(resp *restful.Response, data interface{})
- func IsNotFound(err error) bool
- func ListCommonQuery(rb *restful.RouteBuilder) *restful.RouteBuilder
- func NoContent(resp *restful.Response, data interface{})
- func NotFound(resp *restful.Response, data interface{})
- func NotFoundOrBadRequest(resp *restful.Response, err error)
- func OK(resp *restful.Response, data interface{})
- func OrderOption(req *restful.Request) []client.Option
- func PageSizeOption(req *restful.Request) client.Option
- func ParseError(err error) interface{}
- func PreloadOption(req *restful.Request) client.Option
- func ScopeBelongM2M(ownerModel, selfModel, viaModel interface{}, cond *Cond, ...) func(tx *gorm.DB) *gorm.DB
- func ScopeBelongViaField(model, selfmodel interface{}, cond *Cond, relfield string) func(tx *gorm.DB) *gorm.DB
- func ScopeCondition(conds []*Cond, model interface{}) func(tx *gorm.DB) *gorm.DB
- func ScopeFields(model interface{}, fields []string) func(tx *gorm.DB) *gorm.DB
- func ScopeOmitAssociations(tx *gorm.DB) *gorm.DB
- func ScopeOrder(req *restful.Request, valid []string) func(tx *gorm.DB) *gorm.DB
- func ScopePageSize(req *restful.Request) func(tx *gorm.DB) *gorm.DB
- func ScopePreload(req *restful.Request, validPreloads []string) func(tx *gorm.DB) *gorm.DB
- func ScopeSearch(req *restful.Request, model interface{}, fields []string) func(tx *gorm.DB) *gorm.DB
- func ScopeTable(model interface{}) func(tx *gorm.DB) *gorm.DB
- func SearchOption(req *restful.Request) client.Option
- func ServiceUnavailable(resp *restful.Response, err error)
- func Unauthorized(resp *restful.Response, data interface{})
- func WhereOptions(req *restful.Request, queryWhiteList []string) []client.Option
- type Cond
- type ConditionOperator
- type ListBase
- type PageData
- type PageFilterFunc
- type PageSortFunc
- type RelationCondition
- type RespBase
- type Response
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 CommonOptions ¶
func CommonOptions(req *restful.Request) []client.Option
func IsNotFound ¶
func IsNotFound(err error) bool
func ListCommonQuery ¶
func ListCommonQuery(rb *restful.RouteBuilder) *restful.RouteBuilder
func NotFoundOrBadRequest ¶
func NotFoundOrBadRequest(resp *restful.Response, err error)
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 WhereEqual ¶
func WhereEqual(field string, value interface{}) *Cond
func WhereNameEqual ¶
func WhereNameEqual(value interface{}) *Cond
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
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
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.