Documentation ¶
Index ¶
- type AzureFunctionAction
- type AzureFunctionController
- func (c *AzureFunctionController) ApplyInterceptors(action http.HandlerFunc) http.HandlerFunc
- func (c *AzureFunctionController) ApplyValidation(schema *cvalid.Schema, action http.HandlerFunc) http.HandlerFunc
- func (c *AzureFunctionController) Close(ctx context.Context) error
- func (c *AzureFunctionController) Configure(ctx context.Context, config *cconf.ConfigParams)
- func (c *AzureFunctionController) GenerateActionCmd(name string) string
- func (c *AzureFunctionController) GetActions() []*AzureFunctionAction
- func (c *AzureFunctionController) GetCommand(r *http.Request) (string, error)
- func (c *AzureFunctionController) GetTraceId(r *http.Request) string
- func (c *AzureFunctionController) Instrument(ctx context.Context, name string) *rpctrace.InstrumentTiming
- func (c *AzureFunctionController) IsOpen() bool
- func (c *AzureFunctionController) Open(ctx context.Context) error
- func (c *AzureFunctionController) Register()
- func (c *AzureFunctionController) RegisterAction(name string, schema *cvalid.Schema, action http.HandlerFunc)
- func (c *AzureFunctionController) RegisterActionWithAuth(name string, schema *cvalid.Schema, ...)
- func (c *AzureFunctionController) RegisterInterceptor(cmd string, ...)
- func (c *AzureFunctionController) SetReferences(ctx context.Context, references crefer.IReferences)
- type CommandableAzureFunctionController
- type IAzureFunctionController
- type IAzureFunctionServiceOverrides
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AzureFunctionAction ¶
type AzureFunctionAction struct { // Command to call the action Cmd string // Schema to validate action parameters Schema *cvalid.Schema // Action to be executed Action http.HandlerFunc }
type AzureFunctionController ¶
type AzureFunctionController struct { Overrides IAzureFunctionServiceOverrides // The dependency resolver. DependencyResolver *crefer.DependencyResolver // The logger. Logger *clog.CompositeLogger // The performance counters. Counters *ccount.CompositeCounters // The tracer. Tracer *ctrace.CompositeTracer // contains filtered or unexported fields }
Abstract service that receives remove calls via Azure Function protocol.
This service is intended to work inside AzureFunction container that exposes registered actions externally.
Configuration parameters - dependencies: - service: override for Service dependency References - *:logger:*:*:1.0 (optional) ILogger components to pass log messages - *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements Example: type MyAzureFunctionController struct { *controllers.AzureFunctionController service IMyService } func NewMyAzureFunctionController() *MyAzureFunctionController { c := MyAzureFunctionController{} c.AzureFunctionController = controllers.InheritAzureFunctionController(&c, "v1.mycontroller") c.DependencyResolver.Put(context.Background(), "service", refer.NewDescriptor("mygroup", "service", "default", "*", "1.0")) return &c } func (c *MyAzureFunctionController) SetReferences(ctx context.Context, references refer.IReferences) { c.AzureFunctionController.SetReferences(ctx, references) depRes, depErr := c.DependencyResolver.GetOneRequired("service") if depErr == nil && depRes != nil { c.service = depRes.(IMyService) } } func (c *MyAzureFunctionController) Register() { c.RegisterAction( "get_mydata", nil, func(w http.ResponseWriter, r *http.Request) { var body map[string]any err := AzureFunctionRequestHelper.DecodeBody(r, &body) defer r.Body.Close() ctx := cctx.NewContextWithTraceId(r.Context(), c.GetTraceId(r)) result, err := c.controller.DeleteById( ctx, body, ) HttpResponseSender.SendDeletedResult(w, r, result, err) }, ) } ... controller := NewMyAzureFunctionController() controller.Configure(ctx, config.NewConfigParamsFromTuples( "connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080, )) controller.SetReferences(ctx, refer.NewReferencesFromTuples( refer.NewDescriptor("mygroup", "service", "default", "default", "1.0"), service, )) controller.Open(ctx, "123") fmt.Println("The Azure Function controller is running")
func InheritAzureFunctionController ¶
func InheritAzureFunctionController(overrides IAzureFunctionServiceOverrides, name string) *AzureFunctionController
InheritAzureFunctionController creates new instance of AzureFunctionService
func NewAzureFunctionController ¶
func NewAzureFunctionController(name string) *AzureFunctionController
Creates an instance of this service. Parameters:
- name a controller name to generate action cmd.
func (*AzureFunctionController) ApplyInterceptors ¶
func (c *AzureFunctionController) ApplyInterceptors(action http.HandlerFunc) http.HandlerFunc
func (*AzureFunctionController) ApplyValidation ¶
func (c *AzureFunctionController) ApplyValidation(schema *cvalid.Schema, action http.HandlerFunc) http.HandlerFunc
func (*AzureFunctionController) Close ¶
func (c *AzureFunctionController) Close(ctx context.Context) error
Close method are closes component and frees used resources.
Parameters: - ctx context.Context execution context to trace execution through call chain. Returns: error or nil no errors occurred.
func (*AzureFunctionController) Configure ¶
func (c *AzureFunctionController) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure the component with specified parameters.
see ConfigParams Parameters: - ctx context.Context - config *conf.ConfigParams configuration parameters to set.
func (*AzureFunctionController) GenerateActionCmd ¶
func (c *AzureFunctionController) GenerateActionCmd(name string) string
func (*AzureFunctionController) GetActions ¶
func (c *AzureFunctionController) GetActions() []*AzureFunctionAction
Get all actions supported by the service. Returns an array with supported actions.
func (*AzureFunctionController) GetCommand ¶
func (c *AzureFunctionController) GetCommand(r *http.Request) (string, error)
Returns command from Google Function request. This method can be overloaded in child structs. Parameters:
- req the function request
Returns command from request
func (*AzureFunctionController) GetTraceId ¶
func (c *AzureFunctionController) GetTraceId(r *http.Request) string
Returns traceId from Google Function request. This method can be overloaded in child structs
func (*AzureFunctionController) Instrument ¶
func (c *AzureFunctionController) Instrument(ctx context.Context, name string) *rpctrace.InstrumentTiming
Instrument method are adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement.
Parameters: - ctx context.Context execution context to trace execution through call chain. - name a method name. Returns: Timing object to end the time measurement.
func (*AzureFunctionController) IsOpen ¶
func (c *AzureFunctionController) IsOpen() bool
IsOpen Checks if the component is opened.
Returns: bool true if the component has been opened and false otherwise.
func (*AzureFunctionController) Open ¶
func (c *AzureFunctionController) Open(ctx context.Context) error
Open method are opens the component.
Parameters: - ctx context.Context execution context to trace execution through call chain. Returns: error or nil no errors occured.
func (*AzureFunctionController) Register ¶
func (c *AzureFunctionController) Register()
Registers all service routes in HTTP endpoint. This method is called by the service and must be overridden in child structs.
func (*AzureFunctionController) RegisterAction ¶
func (c *AzureFunctionController) RegisterAction(name string, schema *cvalid.Schema, action http.HandlerFunc)
Registers a action in Google Function function. Parameters:
- name an action name
- schema a validation schema to validate received parameters.
- action an action function that is called when operation is invoked.
func (*AzureFunctionController) RegisterActionWithAuth ¶
func (c *AzureFunctionController) RegisterActionWithAuth(name string, schema *cvalid.Schema, authorize func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc), action http.HandlerFunc)
Registers an action with authorization. Parameters:
- name an action name
- schema a validation schema to validate received parameters.
- authorize an authorization interceptor
- action an action function that is called when operation is invoked.
func (*AzureFunctionController) RegisterInterceptor ¶
func (c *AzureFunctionController) RegisterInterceptor(cmd string, action func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc))
Registers a middleware for actions in Google Function service. Parameters:
- action an action function that is called when middleware is invoked.
func (*AzureFunctionController) SetReferences ¶
func (c *AzureFunctionController) SetReferences(ctx context.Context, references crefer.IReferences)
SetReferences sets references to dependent components.
see IReferences Parameters: - ctx context.Context - references IReferences references to locate the component dependencies.
type CommandableAzureFunctionController ¶
type CommandableAzureFunctionController struct { *AzureFunctionController // contains filtered or unexported fields }
Abstract service that receives commands via Azure Function protocol to operations automatically generated for commands defined in ccomand.ICommandable components. Each command is exposed as invoke method that receives command name and parameters.
Commandable services require only 3 lines of code to implement a robust external Azure Function-based remote interface.
This service is intended to work inside Azure Function container that exploses registered actions externally.
Configuration parameters: - dependencies: - service: override for Service dependency References - *:logger:*:*:1.0 (optional) ILogger components to pass log messages - *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements
see AzureFunctionService
Example: type MyCommandableAzureFunctionController struct { *azuresrv.CommandableAzureFunctionController } func NewMyCommandableAzureFunctionController() *MyCommandableAzureFunctionController { c := MyCommandableAzureFunctionController{} c.CommandableAzureFunctionController = azuresrv.NewCommandableAzureFunctionService("mydata") c.DependencyResolver.Put(context.Background(), "service", crefer.NewDescriptor("mygroup", "service", "default", "*", "*")) return &c } ... service := NewMyCommandableAzureFunctionController() service.SetReferences(crefer.NewReferencesFromTuples( crefer.NewDescriptor("mygroup","service","default","default","1.0"), service, )) service.Open(ctx, "123") fmt.Println("The Azure Function controller is running")
func NewCommandableAzureFunctionController ¶
func NewCommandableAzureFunctionController(name string) *CommandableAzureFunctionController
Creates a new instance of the service. Parameters:
- name a service name.
func (*CommandableAzureFunctionController) GetParameters ¶
func (c *CommandableAzureFunctionController) GetParameters(req *http.Request) *cexec.Parameters
Returns body from Azure Function request. This method can be overloaded in child classes Parameters:
- req Azure Function request
Returns Parameters from request
func (*CommandableAzureFunctionController) Register ¶
func (c *CommandableAzureFunctionController) Register()
Registers all actions in Azure Function.
type IAzureFunctionController ¶
type IAzureFunctionController interface { // Get all actions supported by the service. // Returns an array with supported actions. GetActions() []*AzureFunctionAction }
An interface that allows to integrate Google Function services into Google Function containers and connect their actions to the function calls.
type IAzureFunctionServiceOverrides ¶
type IAzureFunctionServiceOverrides interface {
Register()
}