linker

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: MIT Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

Functions

func EndpointPathFromResource

func EndpointPathFromResource(resourceName string) string

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 NewLinker

func NewLinker(router *web.Router) *Linker

func (*Linker) AddResource

func (l *Linker) AddResource(res Resource)

func (*Linker) AddResources

func (l *Linker) AddResources(resources []Resource)

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

func (*Linker) Router

func (l *Linker) Router() *web.Router

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 Options

type Options struct {
	Linker *Linker
}

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) Destroy

func (r *RepositoryDecoder) Destroy(ctx context.Context, filter *filter.Filter, dest interface{}) error

func (*RepositoryDecoder) DestroyById

func (r *RepositoryDecoder) DestroyById(ctx context.Context, id interface{}) error

func (*RepositoryDecoder) Find

func (r *RepositoryDecoder) Find(ctx context.Context, filter *filter.Filter, dest interface{}) error

func (*RepositoryDecoder) FindById

func (r *RepositoryDecoder) FindById(ctx context.Context, id interface{}, dest interface{}) error

func (*RepositoryDecoder) FindOne

func (r *RepositoryDecoder) FindOne(ctx context.Context, filter *filter.Filter, dest interface{}) error

func (*RepositoryDecoder) Update

func (r *RepositoryDecoder) Update(ctx context.Context, filter *filter.Filter, data interface{}, dest interface{}) error

func (*RepositoryDecoder) UpdateById

func (r *RepositoryDecoder) UpdateById(ctx context.Context, id interface{}, data interface{}, dest interface{}) error

type RepositoryField

type RepositoryField struct {
	Name     string
	Type     string
	Nullable bool
}

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
}

func (*RestResource) Create

func (rest *RestResource) Create(ctx web.Context) error

func (*RestResource) Destroy

func (rest *RestResource) Destroy(ctx web.Context) error

func (*RestResource) List

func (rest *RestResource) List(ctx web.Context) error

func (*RestResource) Show

func (rest *RestResource) Show(ctx web.Context) error

func (*RestResource) Update

func (rest *RestResource) Update(ctx web.Context) error

type SingleResult

type SingleResult map[string]interface{}

func (*SingleResult) Decode

func (s *SingleResult) Decode(dest interface{}) error

Directories

Path Synopsis
datasourcemock
Package datasourcemock is a generated GoMock package.
Package datasourcemock is a generated GoMock package.

Jump to

Keyboard shortcuts

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