Documentation ¶
Index ¶
- func AddStructDecodeHookFunc(f mapstructure.DecodeHookFunc)
- func ConfigureHttpProvider(app *App, config map[string]interface{}) error
- func ConfigureSocketIOProvider(app *App, config map[string]interface{}) error
- func Contains(s []string, e string) bool
- func LoadConfigDirectory(dirPath string) (map[string]map[string]interface{}, error)
- func LoadConfigFile(path string) (map[string]interface{}, error)
- func MapToStruct(data map[string]interface{}, target interface{}) error
- func RequestVars(request http.Request) (requestRegistration, error)
- func StructToMap(data interface{}) (map[string]interface{}, error)
- func ToMap(result interface{}, errs ...error) (map[string]interface{}, error)
- func ToMapSlice(result interface{}, errs ...error) ([]map[string]interface{}, error)
- type App
- func (a *App) AddProvider(name string, provider Provider) error
- func (a *App) AddService(name string, service Service)
- func (a *App) Close() error
- func (a *App) Config(key string) (interface{}, bool)
- func (a *App) Configure(appModule AppModule, config map[string]interface{})
- func (a *App) HandleRequest(provider string, method RestMethod, c Caller, service string, ...)
- func (a *App) Listen()
- func (a *App) LoadConfig() error
- func (a *App) PublishToProviders(room string, event string, data interface{}, path string, ...)
- func (a *App) Service(name string) Service
- func (a *App) ServiceClass(name string) interface{}
- func (a *App) SetAppHooks(hookTree HooksTree)
- func (a *App) SetConfig(key string, value interface{})
- func (a *App) Shutdown(ctx context.Context) error
- func (a *App) TriggerUpdate(ctx *Context)
- type AppModule
- type BasePublishableService
- func (s *BasePublishableService) BeforePublish(topic string, data interface{}, ctx *Context) (interface{}, error)
- func (s *BasePublishableService) Publish(topic string, data interface{}, ctx *Context) ([]string, error)
- func (s *BasePublishableService) RegisterPublishHandler(topic string, handler PublishHandler)
- type BaseService
- type BoolHook
- type Caller
- type Connection
- type Context
- func (c *Context) DataDecode(target interface{}, path ...string) error
- func (c *Context) DataGet(key ...string) interface{}
- func (c *Context) DataHas(key ...string) bool
- func (c *Context) DataMerge(data Data)
- func (c *Context) Deadline() (deadline time.Time, ok bool)
- func (c *Context) Done() <-chan struct{}
- func (c *Context) Err() error
- func (c *Context) Value(key interface{}) interface{}
- type Data
- type Defaulter
- type EventEmitter
- type EventListenerUnregister
- type Hook
- type HookType
- type HooksTree
- type HooksTreeBranch
- type HttpProvider
- type Mappable
- type ModelFactory
- type ModelService
- func (m *ModelService) MapAndValidate(data map[string]interface{}) (interface{}, error)
- func (m *ModelService) MapAndValidateStruct(data map[string]interface{}, target interface{}) error
- func (m *ModelService) MapToModel(data map[string]interface{}) (interface{}, error)
- func (m *ModelService) StructToMap(data interface{}) (map[string]interface{}, error)
- func (m *ModelService) ValidateModel(model interface{}) error
- type NewParamsOpt
- type Params
- func (hc *Params) Copy() Params
- func (hc *Params) Get(key string) interface{}
- func (hc *Params) Has(key string) bool
- func (hc *Params) Lookup(key string) (interface{}, bool)
- func (hc *Params) New() Params
- func (hc *Params) NewWithQuery(query map[string]interface{}) Params
- func (hc *Params) Set(key string, value interface{})
- type Provider
- type PublishHandler
- type PublishableService
- type Query
- type RestMethod
- type Service
- type Setupable
- type SocketIOProvider
- type WritableConnection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddStructDecodeHookFunc ¶
func AddStructDecodeHookFunc(f mapstructure.DecodeHookFunc)
func ConfigureHttpProvider ¶
Use this in combination with `App.Configure` to be able to listen for http requests
func ConfigureSocketIOProvider ¶
ConfigureSocketIOProvider registers a new socketio provider in app
func LoadConfigDirectory ¶
LoadConfigDirectory loads a whole directory of .yaml config files. DEPRECATED! use config.LoadConfigMap instead
func LoadConfigFile ¶
LoadConfigFile loads a yaml config file DEPRECATED! use config.LoadConfigFile instead
func MapToStruct ¶
MapToStruct maps service data into a struct (passed by pointer)
Example: ```` model := Model{} err := MapToStruct(data, &model) ````
func RequestVars ¶
RequestVars parses a http request and extracts service related information
func StructToMap ¶
StructToMap converts a model struct into an interface
func ToMapSlice ¶
Types ¶
type App ¶
type App struct { *EventEmitter // contains filtered or unexported fields }
App is the feathers-go applications instance. Instanciate through NewApp
func (*App) AddProvider ¶
AddProvider adds a network provider to the app.
Primarily called through modules Providers can listen for client connections and are also handling requests
func (*App) AddService ¶
AddService registers a new service for the application
func (*App) Configure ¶
Configure configures modules similar to the original feathers api.
Modules can registers Services, Providers etc.
func (*App) HandleRequest ¶
func (a *App) HandleRequest(provider string, method RestMethod, c Caller, service string, data map[string]interface{}, id string, query map[string]interface{})
HandleRequest handles a request received by a provider. It starts the pipeline and schedules tasks
func (*App) Listen ¶
func (a *App) Listen()
Listen makes the app listen to the port specified in the configuration
func (*App) LoadConfig ¶
LoadConfig loads configuration files from `./config directory`
By default `default.yaml` file is loaded.
It also looks for a environment variable named `APP_ENV`. If it is specified it looks for a config file named after the environment and merges it with default configuration Configuration can be retrieved by `GetConfig`. Keys kan be set and overwritten by `SetConfig` Example: In case of `APP_ENV=development`, looks for `development.yaml` and if it exists merges it with APP_ENV
func (*App) PublishToProviders ¶
func (a *App) PublishToProviders(room string, event string, data interface{}, path string, publishProvider string)
PublishToProviders publishes a event to all providers. Each can decide what to do with the publish by themselfs
func (*App) Service ¶
Service returns a a wrapped service instance of a service for easy calling methods
Wrapping is necessary because otherwise hooks will not be triggered If service does not exist returns nil
func (*App) ServiceClass ¶
ServiceClass returns a service instance as an interface{}
This is useful for parsing a service to a specific interface or struct for calling custom service methods
func (*App) SetAppHooks ¶
SetAppHooks specifies the HookTree of the application (Similar to feathers-go)
func (*App) TriggerUpdate ¶
type AppModule ¶
AppModules is a module which can configure the application
Are supposed to be passed to Configure method of App
type BasePublishableService ¶
type BasePublishableService struct {
// contains filtered or unexported fields
}
BasePublishableService is a basic implementation of PublishableService
func NewBasePublishableService ¶
func NewBasePublishableService() *BasePublishableService
func (*BasePublishableService) BeforePublish ¶
func (s *BasePublishableService) BeforePublish(topic string, data interface{}, ctx *Context) (interface{}, error)
BeforePublish is called before data is published to a topic. data can be manipulated at this point
func (*BasePublishableService) Publish ¶
func (s *BasePublishableService) Publish(topic string, data interface{}, ctx *Context) ([]string, error)
Publish calls PublishHandler if registerd and publishes data to returned topics
func (*BasePublishableService) RegisterPublishHandler ¶
func (s *BasePublishableService) RegisterPublishHandler(topic string, handler PublishHandler)
RegisterPublishHandler registers a new handler for a topic
type BaseService ¶
type BaseService struct { Hooks HooksTree // contains filtered or unexported fields }
BaseService (every service should extend from this)
func (*BaseService) HookTree ¶
func (b *BaseService) HookTree() HooksTree
HookTree returns hook tree of service
func (*BaseService) Name ¶
func (b *BaseService) Name() string
type Caller ¶
type Caller interface { Callback(data interface{}) CallbackError(err error) IsSocket() bool SocketConnection() Connection }
Caller represents a caller of a request. It handles Callbacks
type Connection ¶
type Context ¶
type Context struct { context.Context // App is a reference to the current application instance App App // Data is the data passed from the requesting instance Data Data // Error contains the error which was triggered while executing the route Error error // ID is the id passed fromt the requesting instance ID string // Method containts the method which was called (Get, Patch, Find, etc.) Method RestMethod // Path is the path to the service Path string // Result is the result of the service call (only defined in after hooks) Result interface{} // Service is the called service, but wrapped by the application to also trigger hooks (If you wanna call service class directly for custom methods use ServiceClass) Service Service // ServiceClass is the current service without the wrapper. Do NOT Call Patch, Find, Get, Remove and Update since they do not call hooks! ServiceClass interface{} StatusCode int // Type of the hook (Before or after) Type HookType // Params for this call Params Params }
Context is the context which is passed to every go-feathers hook (Can be used as context.Context)
func (*Context) DataDecode ¶
DataDecode decodes data at `path` to target (pointer)
type EventEmitter ¶
func NewEventEmitter ¶
func NewEventEmitter() *EventEmitter
func (*EventEmitter) Emit ¶
func (el *EventEmitter) Emit(event string, data interface{})
func (*EventEmitter) On ¶
func (el *EventEmitter) On(event string) (<-chan interface{}, EventListenerUnregister)
func (*EventEmitter) Once ¶
func (el *EventEmitter) Once(event string) <-chan interface{}
type EventListenerUnregister ¶
type EventListenerUnregister = func() bool
type HookType ¶
type HookType string
HookType is either `Before, After or Error` and describes the current type of the hook chain
type HooksTree ¶
type HooksTree struct { //Before hooks are executed before service method Before HooksTreeBranch // After hooks are executed after service method After HooksTreeBranch // Error hooks are executed in case hook or service method returns error Error HooksTreeBranch }
HooksTree is the complete hooks definition of a service or the application
func (*HooksTree) Append ¶
func (t *HooksTree) Append(branchType HookType, method RestMethod, hooks []Hook)
func (HooksTree) Branch ¶
func (t HooksTree) Branch(branchType HookType) HooksTreeBranch
type HooksTreeBranch ¶
type HooksTreeBranch struct { // All hooks are executed every time before route specific hooks are executed All []Hook // Find hooks are executed for find calls Find []Hook // Get hooks are executed for get calls Get []Hook // Create hooks are executed for create calls Create []Hook // Patch hooks are executed for patch calls Patch []Hook // Update hooks are executed for update calls Update []Hook // Remove hooks are executed for remove hooks Remove []Hook }
HooksTreeBranch is a single branch of hooks (e.g. for Before, After or Error)
func (*HooksTreeBranch) Append ¶
func (b *HooksTreeBranch) Append(method RestMethod, hooks []Hook)
func (HooksTreeBranch) Branch ¶
func (b HooksTreeBranch) Branch(method RestMethod) []Hook
type HttpProvider ¶
type HttpProvider struct {
// contains filtered or unexported fields
}
HttpProvider is a provider for feathers-go which listens to http requests
func NewHttpProvider ¶
func NewHttpProvider(app *App) *HttpProvider
NewHttpProvider creates a new http provider (injection to app happens through module: `onfigureHttpProvider`)
func (*HttpProvider) Listen ¶
func (h *HttpProvider) Listen(port int, serveMux *http.ServeMux)
Listen is required by Provider interface. It starts listening for incoming http requests
func (*HttpProvider) Publish ¶
func (p *HttpProvider) Publish(room string, event string, data interface{}, path string, provider string)
func (*HttpProvider) ServeHTTP ¶
func (h *HttpProvider) ServeHTTP(response http.ResponseWriter, request *http.Request)
ServceHttp is implemented from http.Handler. It handles a request
type ModelFactory ¶
type ModelFactory = func() interface{}
ModelFactory returns a new instance of the model (used for `ModelService` struct)
type ModelService ¶
type ModelService struct { Model ModelFactory // contains filtered or unexported fields }
ModelService is a service which offers model validation and parsing (create new with `NewModelService`)
func NewModelService ¶
func NewModelService(model ModelFactory) *ModelService
Creates a new ModelService based of a existing model
func (*ModelService) MapAndValidate ¶
func (m *ModelService) MapAndValidate(data map[string]interface{}) (interface{}, error)
MapAndValidate is the same as calling `MapToModel` and `ValidateModel`
func (*ModelService) MapAndValidateStruct ¶
func (m *ModelService) MapAndValidateStruct(data map[string]interface{}, target interface{}) error
MapAndValidate is the same as calling `MapToStruct` and `ValidateModel` on the returned struct
func (*ModelService) MapToModel ¶
func (m *ModelService) MapToModel(data map[string]interface{}) (interface{}, error)
MapToModel parses data passed to a service and returns a model instance
func (*ModelService) StructToMap ¶
func (m *ModelService) StructToMap(data interface{}) (map[string]interface{}, error)
StructToMap converts a model struct into an interface
func (*ModelService) ValidateModel ¶
func (m *ModelService) ValidateModel(model interface{}) error
ValidateModel validates a model based on its validation rules
type NewParamsOpt ¶
type NewParamsOpt = func(params *Params)
func WithOption ¶
func WithOption(option string, value interface{}) NewParamsOpt
func WithQuery ¶
func WithQuery(query Query) NewParamsOpt
type Params ¶
type Params struct { Params map[string]interface{} // Name of provider from which is called from (empty string for server) Provider string // Route which is called (service name) Route string //Caller instance of who has called this Connection Connection // True if connection is socket based IsSocket bool // Headers from client call Headers map[string]string // Query conatains query fields specified by client Query Query User map[string]interface{} Authenticated bool // contains filtered or unexported fields }
Params is the params passed to functions and go-feathers hooks
func NewAuthenticatedParams ¶
func NewParams ¶
func NewParams(opts ...NewParamsOpt) *Params
func NewParamsFrom ¶
func NewParamsFrom(origParams *Params, opts ...NewParamsOpt) *Params
func NewParamsQuery ¶
NewParamsQuery returns a new HookParms struct only containng specified query
func (*Params) NewWithQuery ¶
type Provider ¶
type Provider interface { Listen(port int, mux *http.ServeMux) Publish(room string, event string, data interface{}, path string, provider string) }
Provider handles requests and can listen for new connections
type PublishHandler ¶
PublishHandler is a function which handles a publish of a service and returns a list of rooms to publish to
type PublishableService ¶
type PublishableService interface { RegisterPublishHandler(topic string, handler PublishHandler) Publish(topic string, data interface{}, ctx *Context) ([]string, error) BeforePublish(topic string, data interface{}, ctx *Context) (interface{}, error) }
PublishableService which can publish events
type RestMethod ¶
type RestMethod string
RestMethod represents the method which was called
const ( // Find method retrieves multiple documents Find RestMethod = "find" // Get method retrieves a single document Get RestMethod = "get" // Create method creates a new document Create RestMethod = "create" // Update method replaces a whole doucmnet Update RestMethod = "update" // Patch method inserts new keys or updates existing keys Patch RestMethod = "patch" // Remove method removes a document Remove RestMethod = "remove" // All only represents a hook branch type All RestMethod = "all" )
func (RestMethod) String ¶
func (c RestMethod) String() string
type Service ¶
type Service interface { // Find retrieves multiple entities (`interface{} is a slice`) Find(ctx context.Context, params Params) (interface{}, error) // Get retrives a single entity Get(ctx context.Context, id string, params Params) (interface{}, error) // Create creates a new entity should be created Create(ctx context.Context, data map[string]interface{}, params Params) (interface{}, error) // Update replaces a whole entity Update(ctx context.Context, id string, data map[string]interface{}, params Params) (interface{}, error) // Patch updates or replaces specified entity keys Patch(ctx context.Context, id string, data map[string]interface{}, params Params) (interface{}, error) // Remove removes a entity Remove(ctx context.Context, id string, params Params) (interface{}, error) // HookTree returns the hook tree (mainly uses internally) HookTree() HooksTree // Name returns the name of the current service Name() string // contains filtered or unexported methods }
Service is a callable instance inside feathers which is responslible for a single kind of entity
type SocketIOProvider ¶
type SocketIOProvider struct {
// contains filtered or unexported fields
}
SocketIOProvider handles socket.io connections and events
func NewSocketIOProvider ¶
func NewSocketIOProvider(app *App, config map[string]interface{}) *SocketIOProvider
Creates a new SocketIOProvider instance (use module `ConfigureSocketIOProvider` with apps `Configure` method)
func (*SocketIOProvider) Handle ¶
func (p *SocketIOProvider) Handle(callMethod RestMethod, caller socketCaller, service string, data map[string]interface{}, id string, query map[string]interface{})
Handle handles a new event to a service