services

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandableLambdaService

type CommandableLambdaService struct {
	*LambdaService
	// 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 LambdaService

Example:

type MyCommandableLambdaService struct  {
	*CommandableLambdaService
}

func NewMyCommandableLambdaService() *MyCommandableLambdaService {
	c:= &MyCommandableLambdaService{
		CommandableLambdaService: NewCommandableLambdaService("v1.service")
	}
	c.DependencyResolver.Put(context.Background(),
		"controller",
		cref.NewDescriptor("mygroup","controller","*","*","1.0")
	)
	return c
}

service := NewMyCommandableLambdaService();
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 InheritCommandableLambdaService

func InheritCommandableLambdaService(overrides ILambdaServiceOverrides, name string) *CommandableLambdaService

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

func (*CommandableLambdaService) Register

func (c *CommandableLambdaService) Register()

Registers all actions in AWS Lambda function.

type ILambdaService

type ILambdaService 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 ILambdaServiceOverrides

type ILambdaServiceOverrides 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 LambdaService

type LambdaService struct {
	Overrides ILambdaServiceOverrides

	// 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 MyLambdaService struct  {
      *LambdaService
      controller IMyController
   }
      ...
	func NewMyLambdaService()* MyLambdaService {
	   c:= &MyLambdaService{}
	   c.LambdaService = NewLambdaService("v1.myservice")
	   c.DependencyResolver.Put(
		   context.Background(),
	       "controller",
	       cref.NewDescriptor("mygroup","controller","*","*","1.0")
	   )
	   return c
	}

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

	func (c * LambdaService)  Register() {
		c.RegisterAction("get_mydata", nil,  func(ctx context.Context, params map[string]any)(any, error) {
	        correlationId := params.GetAsString("correlation_id")
	        id := params.GetAsString("id")
			return  c.controller.GetMyData(ctx, correlationId, id)
	    })
	    ...
	}

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

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

func InheritLambdaService

func InheritLambdaService(overrides ILambdaServiceOverrides, name string) *LambdaService

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

func (*LambdaService) Act

func (c *LambdaService) 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 (*LambdaService) ApplyInterceptors

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

func (*LambdaService) ApplyValidation

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

func (*LambdaService) Close

func (c *LambdaService) Close(ctx context.Context, correlationId string) error

Closes component and frees used resources.

Parameters:
	- ctx context.Context	operation context.
	-  correlationId 	(optional) transaction id to trace execution through call chain.

func (*LambdaService) Configure

func (c *LambdaService) 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 (*LambdaService) GenerateActionCmd

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

func (*LambdaService) GetActions

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

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

func (*LambdaService) Instrument

func (c *LambdaService) Instrument(ctx context.Context, correlationId string, name string) *rpcserv.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	operation context.
	-  correlationId     (optional) transaction id to trace execution through call chain.
	-  name              a method name.

returns Timing object to end the time measurement.

func (*LambdaService) IsOpen

func (c *LambdaService) IsOpen() bool

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

func (*LambdaService) Open

func (c *LambdaService) Open(ctx context.Context, correlationId string) error

Opens the component.

Parameters:
	- ctx context.Context	operation context.
	-  correlationId 	(optional) transaction id to trace execution through call chain.

func (*LambdaService) Register

func (c *LambdaService) Register()

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

func (*LambdaService) RegisterAction

func (c *LambdaService) 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 (*LambdaService) RegisterActionWithAuth

func (c *LambdaService) 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 (*LambdaService) RegisterInterceptor

func (c *LambdaService) 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 (*LambdaService) SetReferences

func (c *LambdaService) 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