Documentation ¶
Index ¶
- Constants
- Variables
- func BindRouter(r gin.IRoutes, prefix string, restView IRestView, rest IRest, methods ...uint)
- func MustCopy(toValue, fromValue interface{})
- func NormalizeBatchQuery(in string) ([]string, bool)
- func PaginationQuery(db *gorm.DB, t interface{}, limit, offset int) (int, error)
- func ResponsePagination(ctx *gin.Context, count int, data interface{})
- func WithCacheControl(ctx *gin.Context, d time.Duration)
- type ErrResp
- type IRest
- type IRestView
- type Model
- type OffsetLimitPaginator
- type Rest
- func (r *Rest) Create(ctx *gin.Context, restView IRestView)
- func (r *Rest) Destroy(ctx *gin.Context, restView IRestView, id string)
- func (r *Rest) List(ctx *gin.Context, restView IRestView)
- func (r *Rest) Retrieve(ctx *gin.Context, restView IRestView, id string)
- func (r *Rest) Update(ctx *gin.Context, restView IRestView, id string)
- type RestView
- func (r *RestView) GetCreateSerializer() interface{}
- func (r *RestView) GetModel(isMany bool) interface{}
- func (r *RestView) GetOrderBy() string
- func (r *RestView) GetQuerySet() *gorm.DB
- func (r *RestView) GetSerializer(isMany bool) interface{}
- func (r *RestView) LookupField() string
- func (r *RestView) SaveData(in interface{}) (interface{}, error)
- func (r *RestView) UpdateData(in interface{}, id string) (interface{}, error)
Constants ¶
const ( // List is list method List = iota Create Retrieve Update Destroy )
const (
// ERROR_DUPLICATE is duplicate error code
ERROR_DUPLICATE = "ERROR_DUPLICATE"
)
const HEADER_TOTAL_COUNT = "X-TOTAL-COUNT"
HEADER_TOTAL_COUNT is total count in header for pagination
Variables ¶
var DefaultOffsetLimitPaginator = NewOffsetLimitPaginator(100)
DefaultOffsetLimitPaginator is default OffsetLimitPaginator with 100 items per page
var ReadOnly = []uint{List, Retrieve}
ReadOnly is enum of read only methods
Functions ¶
func BindRouter ¶
BindRouter bind rest group routers
func MustCopy ¶
func MustCopy(toValue, fromValue interface{})
MustCopy must copy a struct or slice to other struct or slice
func NormalizeBatchQuery ¶
func PaginationQuery ¶
PaginationQuery query with pagination, return total count
func ResponsePagination ¶
ResponsePagination response array data with total count in header
Types ¶
type ErrResp ¶
type ErrResp struct { Code string `json:"code"` Message string `json:"message"` Errors interface{} `json:"errors"` }
ErrResp is error response
type IRest ¶
type IRest interface { List(ctx *gin.Context, restView IRestView) Create(ctx *gin.Context, restView IRestView) Retrieve(ctx *gin.Context, restView IRestView, id string) Update(ctx *gin.Context, restView IRestView, id string) Destroy(ctx *gin.Context, restView IRestView, id string) }
IRest is rest interface
type IRestView ¶
type IRestView interface { GetQuerySet() *gorm.DB GetModel(isMany bool) interface{} GetSerializer(isMany bool) interface{} GetCreateSerializer() interface{} SaveData(interface{}) (interface{}, error) UpdateData(interface{}, string) (interface{}, error) GetOrderBy() string LookupField() string }
IRestView is rest view set interface
type Model ¶
type Model struct { ID uint `json:"id" gorm:"primary_key"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt *time.Time `json:"-" sql:"index"` }
Model is same as gorm.Model but with json tag
type OffsetLimitPaginator ¶
type OffsetLimitPaginator struct {
DefaultNumPerPage int
}
OffsetLimitPaginator is struct of OffsetLimit style paginator
func NewOffsetLimitPaginator ¶
func NewOffsetLimitPaginator(defaultNumPerPage int) *OffsetLimitPaginator
NewOffsetLimitPaginator init a OffsetLimitPaginator by default num per page
func (*OffsetLimitPaginator) ParsePagination ¶
func (op *OffsetLimitPaginator) ParsePagination(c *gin.Context) (limit, offset int)
ParsePagination get limit and offset from request
type Rest ¶
type Rest struct{}
Rest is struct impl IRest interface
type RestView ¶
type RestView struct{}
RestView is struct impl IRestView interface
func (*RestView) GetCreateSerializer ¶
func (r *RestView) GetCreateSerializer() interface{}
GetCreateSerializer impl IRestView's GetCreateSerializer
func (*RestView) GetOrderBy ¶
GetOrderBy impl IRestView's GetOrderBy
func (*RestView) GetQuerySet ¶
GetQuerySet impl IRestView's GetQuerySet
func (*RestView) GetSerializer ¶
func (*RestView) LookupField ¶
LookupField impl IRestView's LookupField
func (*RestView) UpdateData ¶
UpdateData impl IRestView's UpdateData