rest

package module
v0.0.0-...-4b7ddd8 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
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]) Apply

func (r *Resource[T]) Apply(rest *REST)

Apply initializes the Resource with the given REST configuration.

func (*Resource[T]) BasePath

func (r *Resource[T]) BasePath() *url.URL

BasePath returns the absolute base path to the resource.

func (*Resource[T]) DB

func (r *Resource[T]) DB() *gorm.DB

DB returns the gorm.DB connection used by the resource, if set.

func (*Resource[T]) GetController

func (r *Resource[T]) GetController() any

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

func (r *Resource[T]) GetRepository() any

GetRepository returns the repository instance associated with the resource. This may handle data storage, querying, or other database operations.

func (*Resource[T]) GetService

func (r *Resource[T]) GetService() any

GetService returns the service instance associated with the resource. This may provide business logic or data processing functionality.

func (*Resource[T]) GetViews

func (r *Resource[T]) GetViews() map[string]any

GetViews returns the view instances associated with the resource. They may be responsible for rendering UI templates or similar tasks.

func (*Resource[T]) HasField

func (r *Resource[T]) HasField(name string) bool

HasField checks if the schema has a field with the given name.

func (*Resource[T]) HasReadableField

func (r *Resource[T]) HasReadableField(name string) bool

HasReadableField checks if the schema has a field with the given name and read permission.

func (*Resource[T]) Name

func (r *Resource[T]) Name() string

Name returns the name of the resource schema.

func (*Resource[T]) NamingStrategy

func (r *Resource[T]) NamingStrategy() schema.Namer

NamingStrategy returns the custom schema.Namer implementation.

func (*Resource[T]) PrimaryField

func (r *Resource[T]) PrimaryField() string

PrimaryField returns the database name of the primary field of the resource.

func (*Resource[T]) PrimaryValue

func (r *Resource[T]) PrimaryValue(entity *T) string

PrimaryValue returns the value of the primary field of the given entity.

func (*Resource[T]) Schema

func (r *Resource[T]) Schema() *schema.Schema

Schema returns the resource schema.

Directories

Path Synopsis
view

Jump to

Keyboard shortcuts

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