Documentation ¶
Index ¶
- Constants
- type REST
- type Resource
- func (r *Resource[T]) Apply(rest *REST)
- func (r *Resource[T]) BasePath() *url.URL
- func (r *Resource[T]) DB() *gorm.DB
- func (r *Resource[T]) GetController() any
- func (r *Resource[T]) GetGroup() *gin.RouterGroup
- func (r *Resource[T]) GetRepository() any
- func (r *Resource[T]) GetService() any
- func (r *Resource[T]) GetViews() map[string]any
- func (r *Resource[T]) HasField(name string) bool
- func (r *Resource[T]) HasReadableField(name string) bool
- func (r *Resource[T]) Name() string
- func (r *Resource[T]) NamingStrategy() schema.Namer
- func (r *Resource[T]) PrimaryField() string
- func (r *Resource[T]) PrimaryValue(entity *T) string
- func (r *Resource[T]) Schema() *schema.Schema
Constants ¶
const ( ErrNoREST = "rest must not be empty" ErrParsingModel = "could not parse model: %v" ErrNoRepository = "repository must not be empty" ErrNoService = "service must not be empty if repository is not gorm.DB" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type REST ¶
type REST struct {
// contains filtered or unexported fields
}
func New ¶
func New(router *gin.RouterGroup, jwtConfig *jwt.Config, authorizationConfig *authorization.Config) *REST
type Resource ¶
type Resource[T any] struct { // Controller handles the business logic for the resource. Controller any // Service provides additional functionalities for the resource. Service any // Views holds different views or representations of the resource depending on their mimetype. Views map[string]any // Repository manages the data persistence for the resource. Repository any // Group is a reference to the used gin.RouterGroup of the resource. Group *gin.RouterGroup // Authorization indicates whether the resource requires authorization. Authorization bool // contains filtered or unexported fields }
Resource represents a generic resource with various components such as Controller, Service, Views, and Repository.
func (*Resource[T]) GetController ¶
GetController returns the controller instance associated with the resource. This is often a handler function that handles HTTP requests or similar events.
func (*Resource[T]) GetGroup ¶
func (r *Resource[T]) GetGroup() *gin.RouterGroup
GetGroup returns the used gin.RouterGround of the resource.
func (*Resource[T]) GetRepository ¶
GetRepository returns the repository instance associated with the resource. This may handle data storage, querying, or other database operations.
func (*Resource[T]) GetService ¶
GetService returns the service instance associated with the resource. This may provide business logic or data processing functionality.
func (*Resource[T]) GetViews ¶
GetViews returns the view instances associated with the resource. They may be responsible for rendering UI templates or similar tasks.
func (*Resource[T]) HasReadableField ¶
HasReadableField checks if the schema has a field with the given name and read permission.
func (*Resource[T]) NamingStrategy ¶
NamingStrategy returns the custom schema.Namer implementation.
func (*Resource[T]) PrimaryField ¶
PrimaryField returns the database name of the primary field of the resource.
func (*Resource[T]) PrimaryValue ¶
PrimaryValue returns the value of the primary field of the given entity.