Documentation
¶
Overview ¶
controllers/generic/controller.go
Index ¶
- Variables
- func ApplyFilters(db *gorm.DB, filters []FilterOptions) *gorm.DB
- func ApplySorting(db *gorm.DB, sorts []SortOptions) *gorm.DB
- func RegisterCRUDRoutes(r *gin.Engine, path string, controller Crudable) *gin.RouterGroup
- func ToSnakeCase(str string) string
- type Authorizer
- type Crudable
- type FilterOptions
- type Model
- type ObjectPermissionCleaner
- type PaginatedResponse
- type Pagination
- type QueryOptions
- type SortOptions
- type ViewSet
- func (c *ViewSet[T]) Create(ctx *gin.Context)
- func (c *ViewSet[T]) Delete(ctx *gin.Context)
- func (c *ViewSet[T]) Full(ctx *gin.Context)
- func (c *ViewSet[T]) GetByID(ctx *gin.Context)
- func (c *ViewSet[T]) GetQueryset(query *gorm.DB) *gorm.DB
- func (c *ViewSet[T]) List(ctx *gin.Context)
- func (c *ViewSet[T]) Schema(ctx *gin.Context)
- func (c *ViewSet[T]) Update(ctx *gin.Context)
- type ViewSetConfig
- type ViewSetOption
Constants ¶
This section is empty.
Variables ¶
var ErrPermissionDenied = errors.New("permission denied")
var ErrUnauthenticated = errors.New("authentication required")
Functions ¶
func ApplyFilters ¶
func ApplyFilters(db *gorm.DB, filters []FilterOptions) *gorm.DB
func ApplySorting ¶ added in v0.1.10
func ApplySorting(db *gorm.DB, sorts []SortOptions) *gorm.DB
func RegisterCRUDRoutes ¶ added in v0.1.14
func ToSnakeCase ¶ added in v0.1.12
Types ¶
type Authorizer ¶ added in v0.2.0
type Authorizer interface {
Authorize(*gin.Context, string, string) error
Scope(*gin.Context, *gorm.DB, string, string) (*gorm.DB, error)
}
Authorizer restricts queries before fetching records or counting pagination. Schema requires model-wide view permission; create requires model-wide add.
type FilterOptions ¶
type ObjectPermissionCleaner ¶ added in v0.2.0
ObjectPermissionCleaner removes grants when an object is permanently deleted. The supplied DB is the same transaction that deleted the object.
type PaginatedResponse ¶
type Pagination ¶
func NewPaginator ¶
func NewPaginator(ctx *gin.Context) Pagination
func (*Pagination) GetResponse ¶
func (p *Pagination) GetResponse(data interface{}) PaginatedResponse
func (*Pagination) PaginatedQueryset ¶
func (p *Pagination) PaginatedQueryset(query *gorm.DB) *gorm.DB
type QueryOptions ¶ added in v0.1.10
type QueryOptions struct {
Filters []FilterOptions
Sorts []SortOptions
}
func ParseQueryParams ¶
func ParseQueryParams(params url.Values) QueryOptions
ParseQueryParams преобразует query-параметры в фильтры
type SortOptions ¶ added in v0.1.10
type ViewSet ¶
type ViewSet[T any] struct { PreloadField []string Authorizer Authorizer PermissionModel string // contains filtered or unexported fields }
func NewViewSet ¶
func NewViewSet[T any](db *gorm.DB, options ...ViewSetOption) *ViewSet[T]
NewViewSet creates a public ViewSet unless authorization is enabled by an option. Options run during construction; initialization errors cause a panic.
type ViewSetConfig ¶ added in v0.2.0
type ViewSetConfig struct {
Authorizer Authorizer
PermissionModel string
}
ViewSetConfig contains the settings shared by ViewSets of all model types.
type ViewSetOption ¶ added in v0.2.0
type ViewSetOption func(*gorm.DB, *ViewSetConfig) error
ViewSetOption configures a ViewSet during construction. An initialization error stops construction with a panic, rather than leaving a public ViewSet.