controllers

package
v0.0.1-6 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandableLambdaController

type CommandableLambdaController struct {
	*LambdaController
	// contains filtered or unexported fields
}

Abstract service that receives commands via AWS Lambda protocol to operations automatically generated for commands defined in 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 Lambda-based remote interface.

This service is intended to work inside LambdaFunction container that exploses registered actions externally.

Configuration parameters

- dependencies:

  • controller: override for Controller dependency

References

  • *:logger:*:*:1.0 (optional) ILogger components to pass log messages
  • *:counters:*:*:1.0 (optional) ICounters components to pass collected measurements

See CommandableLambdaClient See LambdaController

Example:

type MyCommandableLambdaController struct  {
	*CommandableLambdaController
}

func NewMyCommandableLambdaController() *MyCommandableLambdaController {
	c:= &MyCommandableLambdaController{
		CommandableLambdaController: NewCommandableLambdaController("v1.service")
	}
	c.DependencyResolver.Put(context.Background(),
		"controller",
		cref.NewDescriptor("mygroup","controller","*","*","1.0")
	)
	return c
}

service := NewMyCommandableLambdaController();
service.SetReferences(context.Background(), NewReferencesFromTuples(
   NewDescriptor("mygroup","controller","default","default","1.0"), controller
))

service.Open(context.Background(),"123")
fmt.Println("The AWS Lambda 'v1.service' service is running")

func InheritCommandableLambdaController

func InheritCommandableLambdaController(overrides ILambdaControllerOverrides, name string) *CommandableLambdaController

Creates a new instance of the service. - name a service name.

func (*CommandableLambdaController) Register

func (c *CommandableLambdaController) Register()

Registers all actions in AWS Lambda function.

type ILambdaController

type ILambdaController interface {
	// Get all actions supported by the service.
	// Returns an array with supported actions.
	GetActions() []*LambdaAction
}

An interface that allows to integrate lambda services into lambda function containers and connect their actions to the function calls.

type ILambdaControllerOverrides

type ILambdaControllerOverrides interface {
	Register()
}

type LambdaAction

type LambdaAction struct {

	// Command to call the action
	Cmd string

	// Schema to validate action parameters
	Schema *cvalid.Schema

	// Action to be executed
	Action func(ctx context.Context, params map[string]any) (any, error)
}

type LambdaController

type LambdaController struct {
	Overrides ILambdaControllerOverrides

	// The dependency resolver.
	DependencyResolver *cref.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 AWS Lambda protocol.

This service is intended to work inside LambdaFunction container that exploses registered actions externally.

Configuration parameters

  • dependencies:
  • controller: override for Controller dependency

References:

  • *:logger:*:*:1.0 (optional) [[ILogger]] components to pass log messages
  • *:counters:*:*:1.0 (optional) [[ICounters]] components to pass collected measurements

See LambdaClient

Example

   struct MyLambdaController struct  {
      *LambdaController
      service IMyService
   }
      ...
	func NewMyLambdaController()* MyLambdaController {
	   c:= &MyLambdaController{}
	   c.LambdaController = NewLambdaController("v1.mycontroller")
	   c.DependencyResolver.Put(
		   context.Background(),
	       "controller",
	       cref.NewDescriptor("mygroup","controller","*","*","1.0")
	   )
	   return c
	}

	func (c * LambdaController)  SetReferences(ctx context.Context, references IReferences){
	   c.LambdaController.SetReferences(references)
	   ref := c.DependencyResolver.GetRequired("controller")
	   c.service = ref.(IMyService)
	}

	func (c * LambdaController)  Register() {
		c.RegisterAction("get_mydata", nil,  func(ctx context.Context, params map[string]any)(any, error) {
	        traceId := params.GetAsString("trace_id")
	        id := params.GetAsString("id")
			return  c.controller.GetMyData(cctx.NewContextWithTraceId(ctx), id)
	    })
	    ...
	}

	controller := NewMyLambdaController();
	controller.Configure(ctx context.Context, NewConfigParamsFromTuples(
	    "connection.protocol", "http",
	    "connection.host", "localhost",
	    "connection.port", 8080
	))
	controller.SetReferences(context.Background(), cref.NewReferencesFromTuples(
	   cref.NewDescriptor("mygroup","service","default","default","1.0"), service
	))

	controller.Open(context.Background())
	fmt.Println("The Lambda 'v1.myservice' controller is running on port 8080");

func InheritLambdaController

func InheritLambdaController(overrides ILambdaControllerOverrides, name string) *LambdaController

Creates an instance of this service. - name a service name to generate action cmd. LambdaController()

func (*LambdaController) Act

func (c *LambdaController) Act(ctx context.Context, params map[string]any) (any, error)

Calls registered action in this lambda function. "cmd" parameter in the action parameters determin what action shall be called. This method shall only be used in testing.

Parameters:
	- ctx context.Context	operation context.
	-  params action parameters.

func (*LambdaController) ApplyInterceptors

func (c *LambdaController) ApplyInterceptors(action func(context.Context, map[string]any) (any, error)) func(context.Context, map[string]any) (any, error)

func (*LambdaController) ApplyValidation

func (c *LambdaController) ApplyValidation(schema *cvalid.Schema, action func(ctx context.Context, params map[string]any) (any, error)) func(context.Context, map[string]any) (any, error)

func (*LambdaController) Close

func (c *LambdaController) Close(ctx context.Context) error

Closes component and frees used resources.

Parameters:
	- ctx context.Context	execution context to trace execution through call chain.

func (*LambdaController) Configure

func (c *LambdaController) Configure(ctx context.Context, config *cconf.ConfigParams)

Configures component by passing configuration parameters.

Parameters:
	- ctx context.Context	operation context.
	-  config    configuration parameters to be set.

func (*LambdaController) GenerateActionCmd

func (c *LambdaController) GenerateActionCmd(name string) string

func (*LambdaController) GetActions

func (c *LambdaController) GetActions() []*LambdaAction

Get all actions supported by the service. Returns an array with supported actions.

func (*LambdaController) Instrument

func (c *LambdaController) Instrument(ctx context.Context, name string) *rpctrace.InstrumentTiming

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 (*LambdaController) IsOpen

func (c *LambdaController) IsOpen() bool

Checks if the component is opened. Returns true if the component has been opened and false otherwise.

func (*LambdaController) Open

func (c *LambdaController) Open(ctx context.Context) error

Opens the component.

Parameters:
	- ctx context.Context	execution context to trace execution through call chain.

func (*LambdaController) Register

func (c *LambdaController) Register()

Registers all service routes in HTTP endpoint. This method is called by the service and must be overriden in child classes.

func (*LambdaController) RegisterAction

func (c *LambdaController) RegisterAction(name string, schema *cvalid.Schema, action func(ctx context.Context, params map[string]any) (any, error))

Registers a action in AWS Lambda function.

Parameters:
	- ctx context.Context	operation context.
	- name          an action name
	- schema        a validation schema to validate received parameters.
	- action        an action function that is called when operation is invoked.

func (*LambdaController) RegisterActionWithAuth

func (c *LambdaController) RegisterActionWithAuth(name string, schema *cvalid.Schema,
	authorize func(ctx context.Context, params map[string]any, next func(context.Context, map[string]any) (any, error)) (any, error),
	action func(ctx context.Context, params map[string]any) (any, error))

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 (*LambdaController) RegisterInterceptor

func (c *LambdaController) RegisterInterceptor(action func(ctx context.Context, params map[string]any, next func(ctx context.Context, params map[string]any) (any, error)) (any, error))

Registers a middleware for actions in AWS Lambda service. - action an action function that is called when middleware is invoked.

func (*LambdaController) SetReferences

func (c *LambdaController) SetReferences(ctx context.Context, references cref.IReferences)

Sets references to dependent components.

Parameters:
	- ctx context.Context	operation context.
	-  references 	references to locate the component dependencies.

Jump to

Keyboard shortcuts

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