clients

package
v1.0.0-16 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConnectTimeout = 10000
	DefaultTimeout        = 10000
	DefaultRetriesCount   = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudFunctionClient

type CloudFunctionClient struct {
	// The HTTP client.
	Client *http.Client
	// The Google Function connection parameters
	Connection *gcpconn.GcpConnectionParams
	// The number of retries.
	Retries int
	// The default headers to be added to every request.
	Headers *cdata.StringValueMap
	// The connection timeout in milliseconds.
	ConnectTimeout int
	// The invocation timeout in milliseconds.
	Timeout int
	// The remote service uri which is calculated on open.
	Uri string
	// The connection resolver.
	ConnectionResolver *gcpconn.GcpConnectionResolver
	// The dependency resolver.
	DependencyResolver *crefer.DependencyResolver

	// The logger.
	Logger *clog.CompositeLogger
	// The performance counters.
	Counters *ccount.CompositeCounters
	// The tracer.
	Tracer *ctrace.CompositeTracer
}

Abstract client that calls Google Functions.

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

Configuration parameters
	- connections:
		- uri:           full connection uri with specific app and function name
		- protocol:      connection protocol
		- project_id:    is your Google Cloud Platform project ID
		- region:        is the region where your function is deployed
		- function:      is the name of the HTTP function you deployed
		- org_id:        organization name
	- options:
		- retries:               number of retries (default: 3)
		- connect_timeout:       connection timeout in milliseconds (default: 10 sec)
		- timeout:               invocation timeout in milliseconds (default: 10 sec)
	- credentials:
		- account: the service account name
		- auth_token:    Google-generated ID token or null if using custom auth (IAM)

References
	- *:logger:*:*:1.0				(optional) ILogger components to pass log messages
	- *:counters:*:*:1.0			(optional) ICounters components to pass collected measurements
	- *:discovery:*:*:1.0			(optional) IDiscovery services to resolve connection
	- *:credential-store:*:*:1.0	(optional) Credential stores to resolve credentials

see CloudFunction, CommandableGoogleClient

Example:
	type MyCloudFunctionClient struct {
		clients.CloudFunctionClient
	}

	func NewMyCloudFunctionClient() *MyCloudFunctionClient {
		return &MyCloudFunctionClient{
			CloudFunctionClient: *gcpclient.NewCloudFunctionClient(),
		}
	}

	func (c *MyCloudFunctionClient) GetData(ctx context.Context, correlationId string, id string) MyData {
		timing := c.Instrument(ctx, correlationId, "myclient.get_data")

		response, err := c.Call(ctx, "get_data", correlationId, data.NewAnyValueMapFromTuples("id", dummyId))

		defer timing.EndTiming(ctx, err)
		return rpcclients.HandleHttpResponse[MyData](response, correlationId)
	}

	...

	client := NewMyCloudFunctionClient()
	client.Configure(config.NewConfigParamsFromTuples(
		"connection.uri", "http://region-id.cloudfunctions.net/myfunction",
		"connection.protocol", "http",
		"connection.region", "region",
		"connection.function", "myfunction",
		"connection.project_id", "id",
		"credential.auth_token", "XXX",
	))
	result := client.GetData("123", "1")

func NewCloudFunctionClient

func NewCloudFunctionClient() *CloudFunctionClient

Creates new instance of CloudFunctionClient

func (*CloudFunctionClient) AddFilterParams

func (c *CloudFunctionClient) AddFilterParams(params *cdata.StringValueMap, filter *cdata.FilterParams) *cdata.StringValueMap

AddFilterParams method are adds filter parameters (with the same name as they defined) to invocation parameter map.

Parameters:
	- params  *cdata.StringValueMap      invocation parameters.
	- filter  *cdata.FilterParams     (optional) filter parameters
Returns: invocation parameters with added filter parameters.

func (*CloudFunctionClient) AddPagingParams

func (c *CloudFunctionClient) AddPagingParams(params *cdata.StringValueMap, paging *cdata.PagingParams) *cdata.StringValueMap

AddPagingParams method are adds paging parameters (skip, take, total) to invocation parameter map. Parameters:

  • params invocation parameters.
  • paging (optional) paging parameters

Return invocation parameters with added paging parameters.

func (*CloudFunctionClient) Call

func (c *CloudFunctionClient) Call(ctx context.Context, cmd string, correlationId string,
	args *cdata.AnyValueMap) (*http.Response, error)

Performs Google Function invocation. Parameters:

  • cmd an action name to be called.
  • correlationId (optional) transaction id to trace execution through call chain.
  • args action arguments

Returns action result.

func (*CloudFunctionClient) Close

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

Closes component and frees used resources. Parameters:

-correlationId	(optional) transaction id to trace execution through call chain.

func (*CloudFunctionClient) Configure

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

Configure object by passing configuration parameters.

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

func (*CloudFunctionClient) Instrument

func (c *CloudFunctionClient) Instrument(ctx context.Context, correlationId string, name string) *rpcsrv.InstrumentTiming

Instrument method are adds instrumentation to log calls and measure call time. It returns a services.InstrumentTiming object that is used to end the time measurement.

Parameters:
	- ctx context.Context
	- correlationId string (optional) transaction id to trace execution through call chain.
	- name string a method name.
Returns: services.InstrumentTiming object to end the time measurement.

func (*CloudFunctionClient) IsOpen

func (c *CloudFunctionClient) IsOpen() bool

IsOpen Checks if the component is opened.

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

func (*CloudFunctionClient) Open

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

Open opens the component.

Parameters:
	- ctx context.Context
	- correlationId: string transaction id to trace execution through call chain.
Return: error

func (*CloudFunctionClient) SetReferences

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

type CommandableCloudFunctionClient struct {
	*CloudFunctionClient
	// contains filtered or unexported fields
}

Abstract client that calls commandable Google Cloud Functions.

Commandable services are generated automatically for ICommandable objects. Each command is exposed as action determined by "cmd" parameter.

Configuration parameters
	- connections:
		- uri:           full connection uri with specific app and function name
		- protocol:      connection protocol
		- project_id:    is your Google Cloud Platform project ID
		- region:        is the region where your function is deployed
		- function:      is the name of the HTTP function you deployed
		- org_id:        organization name
	- options:
		- retries:               number of retries (default: 3)
		- connect_timeout:       connection timeout in milliseconds (default: 10 sec)
		- timeout:               invocation timeout in milliseconds (default: 10 sec)
	- credentials:
		- account: the service account name
		- auth_token:    Google-generated ID token or null if using custom auth (IAM)

References
	- *:logger:*:*:1.0				(optional) ILogger components to pass log messages
	- *:counters:*:*:1.0			(optional) ICounters components to pass collected measurements
	- *:discovery:*:*:1.0			(optional) IDiscovery services to resolve connection
	- *:credential-store:*:*:1.0	(optional) Credential stores to resolve credentials

see CloudFunction

Exammple:
	type MyCommandableGoogleClient struct {
		clients.CommandableCloudFunctionClient
	}

	func NewMyCommandableGoogleClient() *MyCommandableGoogleClient {
		return &MyCommandableGoogleClient{
			CommandableCloudFunctionClient: *gcpclient.NewCommandableCloudFunctionClient(),
		}
	}

	func (c *MyCommandableGoogleClient) GetData(ctx context.Context, correlationId string, id string) MyData {
		response, err := c.CallCommand(ctx, "dummies.get_dummies", correlationId, cdata.NewAnyValueMapFromTuples("id", id))
		if err != nil {
			return MyData{}, err
		}

		return rpcclient.HandleHttpResponse[MyData](response, correlationId)
	}

	...
	client := NewMyCommandableGoogleClient()
	client.Configure(config.NewConfigParamsFromTuples(
		"connection.uri", "http://region-id.cloudfunctions.net/myfunction",
		"connection.protocol", "http",
		"connection.region", "region",
		"connection.function", "myfunction",
		"connection.project_id", "id",
		"credential.auth_token", "XXX",
	))
	result := client.GetData("123", "1")
	...

func NewCommandableCloudFunctionClient

func NewCommandableCloudFunctionClient(name string) *CommandableCloudFunctionClient

Creates a new instance of this client. Parameters:

  • name a service name.

func (*CommandableCloudFunctionClient) CallCommand

func (c *CommandableCloudFunctionClient) CallCommand(ctx context.Context, cmd string, correlationId string, params *cdata.AnyValueMap) (*http.Response, error)

Calls a remote action in Google Function. The name of the action is added as "cmd" parameter to the action parameters. Parameters:

  • cmd an action name
  • correlationId (optional) transaction id to trace execution through call chain.
  • params command parameters.

Returns action result.

Jump to

Keyboard shortcuts

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