Documentation
¶
Index ¶
- Variables
- func AddToBasePath(basePath string) gin.HandlerFunc
- func BaseURL(c *gin.Context) string
- func CheckFilter(criteria map[string]interface{}) (map[string]interface{}, map[string]interface{}, map[string]interface{})
- func ErrorHook(tonicErrorHook tonic.ErrorHook) tonic.ErrorHook
- func HandlerFindBy(repository ListableRepository) gin.HandlerFunc
- func HandlerFindByPage(repository PageableRepository) gin.HandlerFunc
- func HandlerFindOneBy(repository ListableRepository) gin.HandlerFunc
- func HandlerIndex(links ...ResourceLink) gin.HandlerFunc
- func HandlerRemoveAll(repository TruncatableRepository) gin.HandlerFunc
- func HandlerRemoveOneBy(repository SavableRepository) gin.HandlerFunc
- func InlineFilter(db *gorm.DB, criteria map[string]interface{}) *gorm.DB
- func IsEntityDoesNotExistError(err error) bool
- func JSONBFilter(db *gorm.DB, criteria map[string]interface{}) *gorm.DB
- func NewEntityDoesNotExistError(entity interface{}, criteria map[string]interface{}) error
- func NewUnsupportedEntityError(expected, actual interface{}) error
- func NewUnsupportedIndexError(field string, supported ...string) error
- func RenderHookWrapper(hook tonic.RenderHook) tonic.RenderHook
- func ToJSON(data interface{}) string
- type BaseRepository
- type Entity
- type EntityDoesNotExistError
- type InternalError
- type ListableRepository
- type Page
- type Pageable
- type PageableRepository
- type PagedResources
- type Resource
- type ResourceLink
- type Resourceable
- type SavableRepository
- type SoftDeletableEntity
- type SoftDeletableRepository
- type TruncatableRepository
- type UnsupportedEntityError
- type UnsupportedIndexError
Constants ¶
This section is empty.
Variables ¶
var ErrorCreated = errorCreated("created")
ErrorCreated is raised when no error occurs but a resource has been created (tonic single-status code workaround)
var ErrorGone = errorGone("gone")
ErrorGone is raised when a former resource has been requested but no longer exist
Functions ¶
func AddToBasePath ¶
func AddToBasePath(basePath string) gin.HandlerFunc
AddToBasePath add a subpath to the BasePath stored in the gin context, in order to build hateoas links
func CheckFilter ¶
func CheckFilter(criteria map[string]interface{}) (map[string]interface{}, map[string]interface{}, map[string]interface{})
CheckFilter analyse filters
func HandlerFindBy ¶
func HandlerFindBy(repository ListableRepository) gin.HandlerFunc
HandlerFindBy returns all resources matching path params
func HandlerFindByPage ¶
func HandlerFindByPage(repository PageableRepository) gin.HandlerFunc
HandlerFindByPage returns a filtered and paginated resource list
func HandlerFindOneBy ¶
func HandlerFindOneBy(repository ListableRepository) gin.HandlerFunc
HandlerFindOneBy returns the first resource matching path params
func HandlerIndex ¶
func HandlerIndex(links ...ResourceLink) gin.HandlerFunc
HandlerIndex generates a simple hateoas index
func HandlerRemoveAll ¶
func HandlerRemoveAll(repository TruncatableRepository) gin.HandlerFunc
HandlerRemoveAll removes a whole collection
func HandlerRemoveOneBy ¶
func HandlerRemoveOneBy(repository SavableRepository) gin.HandlerFunc
HandlerRemoveOneBy removes a given resource
func InlineFilter ¶
InlineFilter filter inline filters
func IsEntityDoesNotExistError ¶
IsEntityDoesNotExistError returns true if err is an EntityDoesNotExistError
func JSONBFilter ¶
JSONBFilter filter jsonb
func NewEntityDoesNotExistError ¶
NewEntityDoesNotExistError is a helper to create an EntityDoesNotExistError
func NewUnsupportedEntityError ¶
func NewUnsupportedEntityError(expected, actual interface{}) error
NewUnsupportedEntityError is a helper to create an UnsupportedEntityError
func NewUnsupportedIndexError ¶
NewUnsupportedIndexError is a helper to create an UnsupportedIndexError
func RenderHookWrapper ¶
func RenderHookWrapper(hook tonic.RenderHook) tonic.RenderHook
RenderHookWrapper handles hateoas entity conversion
Types ¶
type BaseRepository ¶
BaseRepository defines a normal repository
type Entity ¶
Entity defines and identifiable REST entity
func FindByPath ¶
func FindByPath(c *gin.Context, repository ListableRepository) (Entity, error)
FindByPath find one entity in the given repository, using paths parameters as matching criteria
type EntityDoesNotExistError ¶
EntityDoesNotExistError is raised when a repository try to read a non existing entity
func (EntityDoesNotExistError) Error ¶
func (err EntityDoesNotExistError) Error() string
Error implements error interface for EntityDoesNotExistError
type InternalError ¶
InternalError all internal error
func (*InternalError) Error ¶
func (err *InternalError) Error() string
Error implements error interface
type ListableRepository ¶
type ListableRepository interface {
BaseRepository
FindBy(map[string]interface{}) (interface{}, error)
FindOneBy(map[string]interface{}) (Entity, error)
}
ListableRepository defines a repository where one can list entities
type Page ¶
type Page struct {
Content interface{}
TotalElements int `json:"totalElements"`
IDs []string `json:"ids,omitempty"`
BasePath string `json:"-"`
Pageable Pageable
}
Page defines a page
func (Page) ToResources ¶
func (page Page) ToResources(baseURL string) PagedResources
ToResources convert receiver page to a hateoas representation
type Pageable ¶
type Pageable struct {
Page int `json:"page" form:"page"`
Size int `json:"size" form:"size"`
Sort string `json:"sort" form:"sort"`
IndexedBy string `json:"indexedBy" form:"indexedBy" default:""`
}
Pageable defines pagination criteria
func (Pageable) GetGormSortClause ¶
func (p Pageable) GetGormSortClause() interface{}
GetGormSortClause returns the SQL-escaped sort clause
func (Pageable) GetSortClause ¶
GetSortClause returns the SQL-escaped sort clause
type PageableRepository ¶
type PageableRepository interface {
BaseRepository
FindPageBy(Pageable, map[string]interface{}) (Page, error)
}
PageableRepository defines a repository that handles pagination
type PagedResources ¶
type PagedResources struct {
Content interface{} `json:"content" binding:"-"`
PageMetadata pageMetadata `json:"pageMetadata" binding:"-"`
Links []ResourceLink `json:"_links" binding:"-"`
}
PagedResources defines a REST representation of paged contents
type Resource ¶
type Resource struct {
Links []ResourceLink `json:"_links,omitempty" gorm:"-" binding:"-"`
}
Resource defines a REST resources links
type ResourceLink ¶
ResourceLink defines relationship between resources
type Resourceable ¶
Resourceable defines a linkable hateoas resource
type SavableRepository ¶
type SavableRepository interface {
ListableRepository
Save(Entity) error
Remove(interface{}) error
}
SavableRepository defines a repository where one can persist or remove entities
type SoftDeletableEntity ¶
SoftDeletableEntity defines a soft deletable REST entity
type SoftDeletableRepository ¶
type SoftDeletableRepository interface {
BaseRepository
FindOneByUnscoped(criteria map[string]interface{}) (SoftDeletableEntity, error)
}
SoftDeletableRepository defines a repository that handles soft delete
type TruncatableRepository ¶
type TruncatableRepository interface {
BaseRepository
Truncate() error
}
TruncatableRepository defines a repository that handles truncation
type UnsupportedEntityError ¶
UnsupportedEntityError is raised when a repository method is called with a wrong type
func (UnsupportedEntityError) Error ¶
func (err UnsupportedEntityError) Error() string
Error implements error interface for UnsupportedEntityError
type UnsupportedIndexError ¶
UnsupportedIndexError is raised when a impossible indexation was requested
func (UnsupportedIndexError) Error ¶
func (err UnsupportedIndexError) Error() string
Error implements error interface for UnsupportedIndexError