services

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

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 AzureFunctionService

type AzureFunctionService 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:
		- 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

Example:
	type MyAzureFunctionService struct {
		*services.AzureFunctionService
		controller IMyController
	}

	func NewMyAzureFunctionService() *MyAzureFunctionService {
		c := MyAzureFunctionService{}

		c.AzureFunctionService = services.InheritAzureFunctionService(&c, "v1.myservice")
		c.DependencyResolver.Put(context.Background(), "controller", refer.NewDescriptor("mygroup", "controller", "default", "*", "1.0"))

		return &c
	}

	func (c *MyAzureFunctionService) SetReferences(ctx context.Context, references refer.IReferences) {
		c.AzureFunctionService.SetReferences(ctx, references)
		depRes, depErr := c.DependencyResolver.GetOneRequired("controller")

		if depErr == nil && depRes != nil {
			c.controller = depRes.(IMyController)
		}
	}

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

				result, err := c.controller.DeleteById(
					r.Context(),
					c.GetCorrelationId(r),
					body,
				)
				HttpResponseSender.SendDeletedResult(w, r, result, err)
			},
		)
	}

	...

	service := NewMyAzureFunctionService()
	service.Configure(ctx, config.NewConfigParamsFromTuples(
		"connection.protocol", "http",
		"connection.host", "localhost",
		"connection.port", 8080,
	))

	service.SetReferences(ctx, refer.NewReferencesFromTuples(
		refer.NewDescriptor("mygroup", "controller", "default", "default", "1.0"), controller,
	))
	service.Open(ctx, "123")
	fmt.Println("The Azure Function service is running")

func InheritAzureFunctionService

func InheritAzureFunctionService(overrides IAzureFunctionServiceOverrides, name string) *AzureFunctionService

InheritAzureFunctionService creates new instance of AzureFunctionService

func NewAzureFunctionService

func NewAzureFunctionService(name string) *AzureFunctionService

Creates an instance of this service. Parameters:

  • name a service name to generate action cmd.

func (*AzureFunctionService) ApplyInterceptors

func (c *AzureFunctionService) ApplyInterceptors(action http.HandlerFunc) http.HandlerFunc

func (*AzureFunctionService) ApplyValidation

func (c *AzureFunctionService) ApplyValidation(schema *cvalid.Schema, action http.HandlerFunc) http.HandlerFunc

func (*AzureFunctionService) Close

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

Close method are closes component and frees used resources.

Parameters:
	- ctx context.Context
	- correlationId (optional) transaction id to trace execution through call chain.
Returns: error or nil no errors occurred.

func (*AzureFunctionService) Configure

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

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

func (*AzureFunctionService) GetActions

func (c *AzureFunctionService) GetActions() []*AzureFunctionAction

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

func (*AzureFunctionService) GetCommand

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

func (c *AzureFunctionService) GetCorrelationId(r *http.Request) string

Returns correlationId from Google Function request. This method can be overloaded in child structs

func (*AzureFunctionService) Instrument

func (c *AzureFunctionService) Instrument(ctx context.Context, correlationId string, name string) *rpcserv.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
	- correlationId     (optional) transaction id to trace execution through call chain.
	- name              a method name.
Returns: Timing object to end the time measurement.

func (*AzureFunctionService) IsOpen

func (c *AzureFunctionService) IsOpen() bool

IsOpen Checks if the component is opened.

Returns: bool true if the component has been opened and false otherwise.

func (*AzureFunctionService) Open

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

Open method are opens the component.

Parameters:
	- ctx context.Context
	- correlationId  string (optional) transaction id to trace execution through call chain.
Returns: error or nil no errors occured.

func (*AzureFunctionService) Register

func (c *AzureFunctionService) Register()

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

func (*AzureFunctionService) RegisterAction

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

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

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

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

type CommandableAzureFunctionService struct {
	*AzureFunctionService
	// 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:
		- 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 AzureFunctionService

Example:
	type MyCommandableAzureFunctionService struct {
		*azuresrv.CommandableAzureFunctionService
	}

	func NewMyCommandableAzureFunctionService() *MyCommandableAzureFunctionService {
		c := MyCommandableAzureFunctionService{}
		c.CommandableAzureFunctionService = azuresrv.NewCommandableAzureFunctionService("mydata")
		c.DependencyResolver.Put(context.Background(), "controller", crefer.NewDescriptor("mygroup", "controller", "default", "*", "*"))
		return &c
	}

	...

	service := NewMyCommandableAzureFunctionService()
	service.SetReferences(crefer.NewReferencesFromTuples(
		crefer.NewDescriptor("mygroup","controller","default","default","1.0"), controller,
	))
	service.Open(ctx, "123")
	fmt.Println("The Azure Function service is running")

func NewCommandableAzureFunctionService

func NewCommandableAzureFunctionService(name string) *CommandableAzureFunctionService

Creates a new instance of the service. Parameters:

  • name a service name.

func (*CommandableAzureFunctionService) GetParameters

Returns body from Azure Function request. This method can be overloaded in child classes Parameters:

  • req Azure Function request

Returns Parameters from request

func (*CommandableAzureFunctionService) Register

func (c *CommandableAzureFunctionService) Register()

Registers all actions in Azure Function.

type IAzureFunctionService

type IAzureFunctionService 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()
}

Jump to

Keyboard shortcuts

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