Documentation ¶
Index ¶
- Variables
- func EndpointPathFromResource(resourceName string) string
- type DefaultOperationHooks
- type DefaultRemoteHooks
- type Linker
- func (l *Linker) AddResource(res Resource)
- func (l *Linker) AddResources(resources []Resource)
- func (l *Linker) Repositories() map[string]*Repository
- func (l *Linker) Repository(name string) *Repository
- func (l *Linker) RepositoryDecoder(name string) *RepositoryDecoder
- func (l *Linker) Router() *web.Router
- type LinkerInstance
- type LinkerPlugin
- func (l *LinkerPlugin) AppendMiddlewares() []web.MiddlewareFunc
- func (l *LinkerPlugin) Instance() interface{}
- func (l *LinkerPlugin) Linker() *Linker
- func (l *LinkerPlugin) Name() string
- func (l *LinkerPlugin) OnCreated(z *zepto.Zepto)
- func (l *LinkerPlugin) OnZeptoInit(z *zepto.Zepto)
- func (l *LinkerPlugin) OnZeptoStart(z *zepto.Zepto)
- func (l *LinkerPlugin) OnZeptoStop(z *zepto.Zepto)
- func (l *LinkerPlugin) PrependMiddlewares() []web.MiddlewareFunc
- type ListResult
- type ManyAffectedResult
- type ManyResults
- type OperationHooks
- type OperationHooksInfo
- type Options
- type RemoteHooks
- type RemoteHooksInfo
- type Repository
- func (r *Repository) Create(ctx context.Context, data interface{}) (*SingleResult, error)
- func (r *Repository) Destroy(ctx context.Context, filter *filter.Filter) (*ManyAffectedResult, error)
- func (r *Repository) DestroyById(ctx context.Context, id interface{}) error
- func (r *Repository) Fields() []RepositoryField
- func (r *Repository) Find(ctx context.Context, filter *filter.Filter) (*ListResult, error)
- func (r *Repository) FindById(ctx context.Context, id interface{}) (*SingleResult, error)
- func (r *Repository) FindOne(ctx context.Context, filter *filter.Filter) (*SingleResult, error)
- func (r *Repository) Update(ctx context.Context, filter *filter.Filter, data interface{}) (*ManyAffectedResult, error)
- func (r *Repository) UpdateById(ctx context.Context, id interface{}, data interface{}) (*SingleResult, error)
- type RepositoryConfig
- type RepositoryDecoder
- func (r *RepositoryDecoder) Create(ctx context.Context, data interface{}, dest interface{}) error
- func (r *RepositoryDecoder) Destroy(ctx context.Context, filter *filter.Filter, dest interface{}) error
- func (r *RepositoryDecoder) DestroyById(ctx context.Context, id interface{}) error
- func (r *RepositoryDecoder) Find(ctx context.Context, filter *filter.Filter, dest interface{}) error
- func (r *RepositoryDecoder) FindById(ctx context.Context, id interface{}, dest interface{}) error
- func (r *RepositoryDecoder) FindOne(ctx context.Context, filter *filter.Filter, dest interface{}) error
- func (r *RepositoryDecoder) Update(ctx context.Context, filter *filter.Filter, data interface{}, dest interface{}) error
- func (r *RepositoryDecoder) UpdateById(ctx context.Context, id interface{}, data interface{}, dest interface{}) error
- type RepositoryField
- type Resource
- type RestResource
- type SingleResult
Constants ¶
This section is empty.
Variables ¶
var ErrUnsuportedMediaType = errors.New(http.StatusText(http.StatusUnsupportedMediaType))
Functions ¶
Types ¶
type DefaultOperationHooks ¶
type DefaultOperationHooks struct{}
func (*DefaultOperationHooks) AfterOperation ¶
func (drh *DefaultOperationHooks) AfterOperation(info OperationHooksInfo) error
func (*DefaultOperationHooks) BeforeOperation ¶
func (drh *DefaultOperationHooks) BeforeOperation(info OperationHooksInfo) error
type DefaultRemoteHooks ¶
type DefaultRemoteHooks struct{}
func (*DefaultRemoteHooks) AfterRemote ¶
func (drh *DefaultRemoteHooks) AfterRemote(info RemoteHooksInfo) error
func (*DefaultRemoteHooks) BeforeRemote ¶
func (drh *DefaultRemoteHooks) BeforeRemote(info RemoteHooksInfo) error
type Linker ¶
type Linker struct {
// contains filtered or unexported fields
}
func (*Linker) AddResource ¶
func (*Linker) AddResources ¶
func (*Linker) Repositories ¶
func (l *Linker) Repositories() map[string]*Repository
func (*Linker) Repository ¶
func (l *Linker) Repository(name string) *Repository
func (*Linker) RepositoryDecoder ¶
func (l *Linker) RepositoryDecoder(name string) *RepositoryDecoder
type LinkerInstance ¶
type LinkerInstance interface { Repository(name string) *Repository RepositoryDecoder(name string) *RepositoryDecoder }
func InstanceFromCtx ¶
func InstanceFromCtx(ctx web.Context) LinkerInstance
type LinkerPlugin ¶
type LinkerPlugin struct {
// contains filtered or unexported fields
}
func NewLinkerPlugin ¶
func NewLinkerPlugin(opts Options) *LinkerPlugin
func (*LinkerPlugin) AppendMiddlewares ¶
func (l *LinkerPlugin) AppendMiddlewares() []web.MiddlewareFunc
func (*LinkerPlugin) Instance ¶
func (l *LinkerPlugin) Instance() interface{}
func (*LinkerPlugin) Linker ¶
func (l *LinkerPlugin) Linker() *Linker
func (*LinkerPlugin) Name ¶
func (l *LinkerPlugin) Name() string
func (*LinkerPlugin) OnCreated ¶
func (l *LinkerPlugin) OnCreated(z *zepto.Zepto)
func (*LinkerPlugin) OnZeptoInit ¶
func (l *LinkerPlugin) OnZeptoInit(z *zepto.Zepto)
func (*LinkerPlugin) OnZeptoStart ¶
func (l *LinkerPlugin) OnZeptoStart(z *zepto.Zepto)
func (*LinkerPlugin) OnZeptoStop ¶
func (l *LinkerPlugin) OnZeptoStop(z *zepto.Zepto)
func (*LinkerPlugin) PrependMiddlewares ¶
func (l *LinkerPlugin) PrependMiddlewares() []web.MiddlewareFunc
type ListResult ¶
type ListResult struct { Data ManyResults `json:"data"` Count int64 `json:"count"` }
func (*ListResult) Decode ¶
func (s *ListResult) Decode(dest interface{}) error
type ManyAffectedResult ¶
type ManyAffectedResult struct {
TotalAffected int64 `json:"total_affected"`
}
func (*ManyAffectedResult) Decode ¶
func (mar *ManyAffectedResult) Decode(dest interface{}) error
type ManyResults ¶
type ManyResults []*SingleResult
func (*ManyResults) Decode ¶
func (m *ManyResults) Decode(dest interface{}) error
type OperationHooks ¶
type OperationHooks interface { BeforeOperation(info OperationHooksInfo) error AfterOperation(info OperationHooksInfo) error }
OperationHooks is used to intercept before and after an operation to datasource (Gorm, etc)
It doesn't know what is HTTP and doesn't have context and access to HTTP information.
Use OperationHooks when you need to intercept a query in all cases, from the default HTTP request and from the programmatically call like:
Linker.Respository("User").Find(...)
type OperationHooksInfo ¶
type OperationHooksInfo struct { // Type of operation: FindOne, Find, Update, Create or Destroy Operation string // Current Resource Name ResourceName string // Current Resource ID (Only present in FindOne, Update or Destroy operations) ResourceID *string // Data used to perform the OperationHooks Create and Update Data *map[string]interface{} // Result from the AfterOperation it can be a SingleResult or a ListResult depending on the operation Result *map[string]interface{} /* QueryContext is the object used to apply the Linker filters. Use this object to intercept or change where, limit, skip and include filters before perform the OperationHooks. */ QueryContext *datasource.QueryContext // Linker Plugin Instance. You can use it to do another queries inside hooks Linker LinkerInstance }
type RemoteHooks ¶
type RemoteHooks interface { BeforeRemote(info RemoteHooksInfo) error AfterRemote(info RemoteHooksInfo) error }
RemoteHooks is used to intercept before and after a HTTP Remote request
It has access to HTTP request and you can use all Zepto web features like: cookies, sessions, headers, plugins, etc.
Use RemoteHooks to restrict some users to access specifics endpoints or to customize the final body json sent to user.
When BeforeRemote or AfterRemote returns an error, the linker will not continue and return http error.
Note: This is not a controller. Although it is possible, we do not recommend calling the render here. You can only prevent the request from happening, but if you need to return a body completely different from Linker, it is recommended to create a controller and route using the common Zepto pathways.
type RemoteHooksInfo ¶
type RemoteHooksInfo struct { // Type of endpoint: List, Show, Create, Update or Destroy Endpoint string // Zepto Web Context Ctx web.Context // Current Resource Name ResourceName string // Current Resource ID (Only present in Show, Update and Destroy endpoints) ResourceID *string // Data parsed from JSON body (Only useful in Create and Update endpoints) Data *map[string]interface{} // Result data that will be encoded to JSON and be sent to the user Result *map[string]interface{} // Linker Plugin Instance. You can use it to do another queries inside hooks Linker LinkerInstance }
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶
func NewRepository(config RepositoryConfig) *Repository
func (*Repository) Create ¶
func (r *Repository) Create(ctx context.Context, data interface{}) (*SingleResult, error)
func (*Repository) Destroy ¶
func (r *Repository) Destroy(ctx context.Context, filter *filter.Filter) (*ManyAffectedResult, error)
func (*Repository) DestroyById ¶
func (r *Repository) DestroyById(ctx context.Context, id interface{}) error
func (*Repository) Fields ¶
func (r *Repository) Fields() []RepositoryField
func (*Repository) Find ¶
func (r *Repository) Find(ctx context.Context, filter *filter.Filter) (*ListResult, error)
func (*Repository) FindById ¶
func (r *Repository) FindById(ctx context.Context, id interface{}) (*SingleResult, error)
func (*Repository) FindOne ¶
func (r *Repository) FindOne(ctx context.Context, filter *filter.Filter) (*SingleResult, error)
func (*Repository) Update ¶
func (r *Repository) Update(ctx context.Context, filter *filter.Filter, data interface{}) (*ManyAffectedResult, error)
func (*Repository) UpdateById ¶
func (r *Repository) UpdateById(ctx context.Context, id interface{}, data interface{}) (*SingleResult, error)
type RepositoryConfig ¶
type RepositoryConfig struct { ResourceName string Linker LinkerInstance Datasource datasource.Datasource OperationHooks OperationHooks }
type RepositoryDecoder ¶
type RepositoryDecoder struct {
Repo *Repository
}
func (*RepositoryDecoder) Create ¶
func (r *RepositoryDecoder) Create(ctx context.Context, data interface{}, dest interface{}) error
func (*RepositoryDecoder) DestroyById ¶
func (r *RepositoryDecoder) DestroyById(ctx context.Context, id interface{}) error
func (*RepositoryDecoder) FindById ¶
func (r *RepositoryDecoder) FindById(ctx context.Context, id interface{}, dest interface{}) error
func (*RepositoryDecoder) UpdateById ¶
func (r *RepositoryDecoder) UpdateById(ctx context.Context, id interface{}, data interface{}, dest interface{}) error
type RepositoryField ¶
type Resource ¶
type Resource struct { Name string Datasource datasource.Datasource RemoteHooks RemoteHooks OperationHooks OperationHooks }
type RestResource ¶
type RestResource struct { ResourceName string Linker LinkerInstance Repository *Repository RemoteHooks RemoteHooks }
type SingleResult ¶
type SingleResult map[string]interface{}
func (*SingleResult) Decode ¶
func (s *SingleResult) Decode(dest interface{}) error
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
datasourcemock
Package datasourcemock is a generated GoMock package.
|
Package datasourcemock is a generated GoMock package. |