containers

package
v1.1.0-3 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudFunction

type CloudFunction struct {
	*ccont.Container

	Overrides ICloudFunctionOverrides
	// The dependency resolver.
	DependencyResolver *crefer.DependencyResolver
	// The performanc counters.
	Counters *ccount.CompositeCounters
	// The tracer.
	Tracer *ctrace.CompositeTracer
	// The map of registred validation schemas.
	Schemas map[string]*cvalid.Schema
	// The map of registered actions.
	Actions map[string]http.HandlerFunc
	// contains filtered or unexported fields
}

Abstract Google Function, that acts as a container to instantiate and run components and expose them via external entry point.

When handling calls "cmd" parameter determines which what action shall be called, while other parameters are passed to the action itself.

Container configuration for this Google Function is stored in "./config/config.yml" file. But this path can be overriden by CONFIG_PATH environment variable.

References
	- *:logger:*:*:1.0							(optional) ILogger components to pass log messages
	- *:counters:*:*:1.0						(optional) ICounters components to pass collected measurements
	- *:controller:cloudfunc:*:1.0				(optional) ICloudFunctionController controllers to handle action requests
	- *:controller:commandable-cloudfunc:*:1.0	(optional) ICloudFunctionController controllers to handle action requests

Example:
	type MyCloudFunction struct {
		*containers.CloudFunction
	}

	func NewMyCloudFunction() *MyCloudFunction {
		c := MyCloudFunction{}
		c.CloudFunction = containers.NewCloudFunctionWithParams("mygroup", "MyGroup Google Function")

		return &c
	}

	...

	cloudFunction := NewMyCloudFunction()
	cloudFunction.Run(ctx)
	fmt.Println("MyCloudFunction is started")

func InheritCloudFunction

func InheritCloudFunction(overrides ICloudFunctionOverrides) *CloudFunction

InheritCloudFunction creates new instance of CloudFunction

func InheritCloudFunctionWithParams

func InheritCloudFunctionWithParams(overrides ICloudFunctionOverrides, name string, description string) *CloudFunction

InheritCloudFunction creates new instance of CloudFunction Parameters:

  • name (optional) a container name (accessible via ContextInfo)
  • description (optional) a container description (accessible via ContextInfo)

func NewCloudFunction

func NewCloudFunction() *CloudFunction

Creates a new instance of this Google Function function.

func NewCloudFunctionWithParams

func NewCloudFunctionWithParams(name string, description string) *CloudFunction

Creates a new instance of this Google Function function. Parameters:

  • name (optional) a container name (accessible via ContextInfo)
  • description (optional) a container description (accessible via ContextInfo)

func (*CloudFunction) Execute

func (c *CloudFunction) Execute(res http.ResponseWriter, req *http.Request)

Executes this Google Function and returns the result. This method can be overloaded in child classes if they need to change the default behavior

Parameters:
	- res the function response
	- req the function request

func (*CloudFunction) GetCommand

func (c *CloudFunction) GetCommand(r *http.Request) (string, error)

Returns command from Google Function request. This method can be overloaded in child classes

Parameters:
	- req	Googel Function request

Returns command from request

func (*CloudFunction) GetHandler

func (c *CloudFunction) GetHandler() http.HandlerFunc

Gets entry point into this Google Function.

Parameters:
	- res the function response
	- req the function request

func (*CloudFunction) GetTraceId

func (c *CloudFunction) GetTraceId(r *http.Request) string

Returns traceId from Googel Function request. This method can be overloaded in child classes

Parameters:
	- req	Googel Function request

Returns traceId from request

func (*CloudFunction) Instrument

func (c *CloudFunction) 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 a context to trace execution through call chain.
	- name              a method name.
Returns: Timing object to end the time measurement.

func (*CloudFunction) Open

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

Open opens the component.

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

func (*CloudFunction) Register

func (c *CloudFunction) Register()

func (*CloudFunction) RegisterAction deprecated

func (c *CloudFunction) RegisterAction(cmd string, schema *cvalid.Schema, action http.HandlerFunc)

Registers an action in this Google Function.

Parameters:
	- cmd		a action/command name.
	- schema	a validation schema to validate received parameters.
	- action	an action function that is called when action is invoked.

Deprecated: This method has been deprecated. Use CloudFunctionService instead.

func (*CloudFunction) RegisterControllers

func (c *CloudFunction) RegisterControllers()

Registers all Google Function controllers in the container.

func (*CloudFunction) Run

func (c *CloudFunction) Run(ctx context.Context)

Runs this Google Function, loads container configuration, instantiate components and manage their lifecycle, makes this function ready to access action calls.

Parameters:
	- ctx context.Context

func (*CloudFunction) SetConfigPath

func (c *CloudFunction) SetConfigPath(configPath string)

SetConfigPath set path for configuration file Parameters:

  • configPath path to config file

func (*CloudFunction) SetReferences

func (c *CloudFunction) 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 CommandableCloudFunction deprecated

type CommandableCloudFunction struct {
	*CloudFunction
}

Abstract Google Function function, that acts as a container to instantiate and run components and expose them via external entry point. All actions are automatically generated for commands defined in ICommandable components. Each command is exposed as an action defined by "cmd" parameter.

Container configuration for this Google Function is stored in "./config/config.yml" file. But this path can be overridden by <code>CONFIG_PATH</code> environment variable.

References
	- *:logger:*:*:1.0							(optional) ILogger components to pass log messages
	- *:counters:*:*:1.0						(optional) ICounters components to pass collected measurements
	- *:controller:cloudfunc:*:1.0       		(optional) ICloudFunctionController controllers to handle action requests
	- *:controller:commandable-cloudfunc:*:1.0	(optional) ICloudFunctionController controllers to handle action requests

Example:
	type MyCloudFunction struct {
		*containers.CommandableCloudFunction
		controller IMyController
	}

	func NewMyCloudFunction() *MyCloudFunction {
		c := MyCloudFunction{}
		c.CloudFunction = containers.NewCommandableCloudFunctionWithParams("mygroup", "MyGroup CloudFunction")

		return &c
	}

	...

	cloudFunction := NewMyCloudFunction()
	cloudFunction.Run(ctx)
	fmt.Println("MyCloudFunction is started")

Deprecated: This component has been deprecated. Use CloudFunctionService instead.

func NewCommandableCloudFunction

func NewCommandableCloudFunction() *CommandableCloudFunction

Creates a new instance of this Google Function.

func NewCommandableCloudFunctionWithParams

func NewCommandableCloudFunctionWithParams(name string, description string) *CommandableCloudFunction

Creates a new instance of this Google Function. Parameters:

  • name (optional) a container name (accessible via ContextInfo)
  • description (optional) a container description (accessible via ContextInfo)

func (*CommandableCloudFunction) GetParameters

func (c *CommandableCloudFunction) GetParameters(req *http.Request) *cexec.Parameters

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

  • req Googl Function request

Returns Parameters from request

func (*CommandableCloudFunction) Register deprecated

func (c *CommandableCloudFunction) Register()

Registers all actions in this Google Function.

Deprecated: Overloading of this method has been deprecated. Use CloudFunctionService instead.

type ICloudFunctionOverrides

type ICloudFunctionOverrides interface {
	crefer.IReferenceable
	// Registers all actions in this Google Function.
	//
	// Depecated: Overloading of this method has been deprecated. Use CloudFunctionService instead.
	Register()
}

Jump to

Keyboard shortcuts

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