Documentation ¶
Index ¶
- type CommandableGrpcController
- type GrpcController
- func (c *GrpcController) Close(ctx context.Context) (err error)
- func (c *GrpcController) Configure(ctx context.Context, config *cconf.ConfigParams)
- func (c *GrpcController) Instrument(ctx context.Context, name string) *rpctrace.InstrumentTiming
- func (c *GrpcController) IsOpen() bool
- func (c *GrpcController) Open(ctx context.Context) (err error)
- func (c *GrpcController) Register()
- func (c *GrpcController) RegisterCommandableMethod(method string, schema *cvalid.Schema, ...)
- func (c *GrpcController) RegisterUnaryInterceptor(...)
- func (c *GrpcController) SetReferences(ctx context.Context, references cref.IReferences)
- func (c *GrpcController) UnsetReferences()
- func (c *GrpcController) ValidateRequest(request any, schema *cvalid.Schema) error
- type GrpcEndpoint
- func (c *GrpcEndpoint) AddInterceptors(interceptors ...grpc.ServerOption)
- func (c *GrpcEndpoint) Close(ctx context.Context) (err error)
- func (c *GrpcEndpoint) Configure(ctx context.Context, config *cconf.ConfigParams)
- func (c *GrpcEndpoint) GetServer() *grpc.Server
- func (c *GrpcEndpoint) IsOpen() bool
- func (c *GrpcEndpoint) Open(ctx context.Context) (err error)
- func (c *GrpcEndpoint) Register(registration IRegisterable)
- func (c *GrpcEndpoint) RegisterCommandableMethod(method string, schema *cvalid.Schema, ...)
- func (c *GrpcEndpoint) RegisterController(sd *grpc.ServiceDesc, implementation any)
- func (c *GrpcEndpoint) SetReferences(ctx context.Context, references cref.IReferences)
- func (c *GrpcEndpoint) Unregister(registration IRegisterable)
- type IGrpcControllerOverrides
- type IRegisterable
- type InvokeComandMediator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandableGrpcController ¶
type CommandableGrpcController struct { *GrpcController // contains filtered or unexported fields }
type MyCommandableGrpcController struct { *CommandableGrpcController } func NewCommandableGrpcController() *CommandableGrpcController { c := DumMyCommandableGrpcController{} c.CommandableGrpcController = grpcservices.NewCommandableGrpcController("mycontroller") c.DependencyResolver.Put("service", cref.NewDescriptor("mygroup", "service", "default", "*", "*")) return &c }
controller := NewMyCommandableGrpcController(); controller.Configure(ctx, cconf.NewConfigParamsFromTuples(
"connection.protocol", "http", "connection.host", "localhost", "connection.port", "8080",
)); controller.SetReferences(ctx, cref.NewReferencesFromTuples(
cref.NewDescriptor("mygroup","controller","default","default","1.0"), service
));
opnErr := controller.Open(ctx)
if opnErr == nil { fmt.Println("The GRPC controller is running on port 8080"); }
func InheritCommandableGrpcController ¶
func InheritCommandableGrpcController(overrides IGrpcControllerOverrides, name string) *CommandableGrpcController
InheritCommandableGrpcController method are creates a new instance of the service.
- name a service name.
func (*CommandableGrpcController) Register ¶
func (c *CommandableGrpcController) Register()
Register method are registers all service command in gRPC endpoint.
type GrpcController ¶
type GrpcController struct { Overrides IGrpcControllerOverrides // The GRPC endpoint that exposes c service. Endpoint *GrpcEndpoint // 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 }
GrpcController abstract controller that receives remove calls via GRPC protocol.
Configuration parameters: - dependencies: - endpoint: override for GRPC Endpoint dependency - service: override for Controller dependency - connection(s): - discovery_key: (optional) a key to retrieve the connection from connect.idiscovery.html IDiscovery - protocol: connection protocol: http or https - host: host name or IP address - port: port number - uri: resource URI or connection string with all parameters in it - credential - the HTTPS credentials: - ssl_key_file: the SSL private key in PEM - ssl_crt_file: the SSL certificate in PEM - ssl_ca_file: the certificate authorities (root cerfiticates) in PEM 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 controllers to resolve connection - *:endpoint:grpc:*:1.0 (optional) GrpcEndpoint reference
See GrpcClient ¶
Example:
type MyGrpcController struct{ *GrpcController service IMyService; } ... func NewMyGrpcController() *MyGrpcController { c := MyGrpcController{} c.GrpcController = grpccontrollers.NewGrpcController("Mydata.Mydatas") c.GrpcController.IRegisterable = &c c.numberOfCalls = 0 c.DependencyResolver.Put(context.Context(), "service", cref.NewDescriptor("mygroup", "service", "*", "*", "*")) return &c } func (c*MyGrpcController) SetReferences(ctx context.Context, references: IReferences) { c.service.SetReferences(references); resolv, err := c.DependencyResolver.GetOneRequired("service") if err == nil && resolv != nil { c.service = resolv.(grpctest.IMyService) return } panic("Can't resolve 'service' reference") } func (c*MyGrpcController) Register() { protos.RegisterMyDataServer(c.Endpoint.GetServer(), c) ... } service := NewMyGrpcController(); service.Configure(ctx, cconf.NewConfigParamsFromTuples( "connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080, )); service.SetReferences(ctx, cref.NewReferencesFromTuples( cref.NewDescriptor("mygroup","controller","default","default","1.0"), controller )); err := service.Open(ctx) if err == nil { fmt.Println("The GRPC service is running on port 8080"); }
func InheritGrpcController ¶
func InheritGrpcController(overrides IGrpcControllerOverrides, serviceName string) *GrpcController
InheritGrpcController methods are creates new instance NewGrpcController Parameters:
- overrides a reference to child class that overrides virtual methods
- serviceName string
service name from XYZ.pb.go, set "" for use default gRPC commandable protobuf Return *GrpcController
func (*GrpcController) Close ¶
func (c *GrpcController) Close(ctx context.Context) (err error)
Close method are closes component and frees used resources.
Parameters: - ctx context.Context a context to trace execution through call chain.
Returns: error or nil no errors occured.
func (*GrpcController) Configure ¶
func (c *GrpcController) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure method are configures component by passing configuration parameters.
Parameters: - ctx context.Context operation context - config configuration parameters to be set.
func (*GrpcController) Instrument ¶
func (c *GrpcController) 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.
Return Timing object to end the time measurement.
func (*GrpcController) IsOpen ¶
func (c *GrpcController) IsOpen() bool
IsOpen method are checks if the component is opened. Return true if the component has been opened and false otherwise.
func (*GrpcController) Open ¶
func (c *GrpcController) Open(ctx context.Context) (err error)
Open method are opens the component.
Parameters: - ctx context.Context a context to trace execution through call chain.
Returns: error or nil no errors occured.
func (*GrpcController) Register ¶
func (c *GrpcController) Register()
Register method are registers all service routes in HTTP endpoint.
func (*GrpcController) RegisterCommandableMethod ¶
func (c *GrpcController) RegisterCommandableMethod(method string, schema *cvalid.Schema, action func(ctx context.Context, data *crun.Parameters) (result any, err error))
RegisterCommandableMethod method are registers a commandable method in c objects GRPC server (service) by the given name.,
Parameters: - ctx context.Context operation context - method the GRPC method name. - schema the schema to use for parameter validation. - action the action to perform at the given route.
func (*GrpcController) RegisterUnaryInterceptor ¶
func (c *GrpcController) RegisterUnaryInterceptor(action func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error))
Registers a middleware for methods in GRPC endpoint.
Parameters: - action an action function that is called when middleware is invoked.
func (*GrpcController) SetReferences ¶
func (c *GrpcController) SetReferences(ctx context.Context, references cref.IReferences)
SetReferences method are sets references to dependent components.
Parameters: - ctx context.Context operation context - references references to locate the component dependencies.
func (*GrpcController) UnsetReferences ¶
func (c *GrpcController) UnsetReferences()
UnsetReferences method are unsets (clears) previously set references to dependent components.
func (*GrpcController) ValidateRequest ¶
func (c *GrpcController) ValidateRequest(request any, schema *cvalid.Schema) error
type GrpcEndpoint ¶
type GrpcEndpoint struct {
// contains filtered or unexported fields
}
GrpcEndpoint used for creating GRPC endpoints. An endpoint is a URL, at which a given controller can be accessed by a client.
Configuration parameters:
Parameters to pass to the configure method for component configuration:
Configuration parameters - connection(s) - the connection resolver"s connections: - discovery_key - the key to use for connection resolving in a discovery controller; - protocol - the connection"s protocol - host - the target host; - port - the target port; - uri - the target URI. - credential(s) - the HTTPS credentials: - ssl_key_file - the SSL private key in PEM - ssl_crt_file - the SSL certificate in PEM - ssl_ca_file - the certificate authorities (root cerfiticates) in PEM References: - logger: "*:logger:*:*:1.0"; - counters: "*:counters:*:*:1.0"; - discovery: "*:discovery:*:*:1.0" (for the connection resolver). Examples: func (c* Endpoint) MyMethod(ctx context.Context, config ConfigParams, references IReferences) { endpoint := NewGrpcEndpoint(); if c.config != nil { endpoint.Configure(ctx, c._config); } if c.references != nil { endpoint.SetReferences(ctx, c.references); } ... err := c.endpoint.Open(ctx) if err != nil { // error ocured return err } c.Opened = true return nil ... }
func NewGrpcEndpoint ¶
func NewGrpcEndpoint() *GrpcEndpoint
NewGrpcEndpoint method are creates new instance of GrpcEndpoint
func (*GrpcEndpoint) AddInterceptors ¶
func (c *GrpcEndpoint) AddInterceptors(interceptors ...grpc.ServerOption)
AddInterceptors method are registers a middleware for methods in GRPC endpoint. See https://github.com/grpc/grpc-go/tree/master/examples/features/interceptor Parameters:
- interceptors ...grpc.ServerOption
interceptor functions (Stream or Unary use grpc.UnaryInterceptor() or grpc.StreamInterceptor() for inflate in grpc.ServerOption)
func (*GrpcEndpoint) Close ¶
func (c *GrpcEndpoint) Close(ctx context.Context) (err error)
Close methods are closes c endpoint and the GRPC server (controller) that was opened earlier.
Parameters: - ctx context.Context a context to trace execution through call chain.
Returns: an error if one is raised.
func (*GrpcEndpoint) Configure ¶
func (c *GrpcEndpoint) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure method are configures c HttpEndpoint using the given configuration parameters. Configuration parameters:
- connection(s) - the connection resolver"s connections;
- "connection.discovery_key" - the key to use for connection resolving in a discovery controller;
- "connection.protocol" - the connection"s protocol;
- "connection.host" - the target host;
- "connection.port" - the target port;
- "connection.uri" - the target URI.
- "credential.ssl_key_file" - SSL private key in PEM
- "credential.ssl_crt_file" - SSL certificate in PEM
- "credential.ssl_ca_file" - Certificate authority (root certificate) in PEM Parameters:
- ctx context.Context operation context
- config configuration parameters, containing a "connection(s)" section.
See ConfigParams (in the PipServices "Commons" package)
func (*GrpcEndpoint) GetServer ¶
func (c *GrpcEndpoint) GetServer() *grpc.Server
GetServer return working gRPC server for register controllers Note: this server is async working in goroutione, wrap into locks if you want change this variable Returns *grpc.Server
func (*GrpcEndpoint) IsOpen ¶
func (c *GrpcEndpoint) IsOpen() bool
IsOpen method are return whether or not c endpoint is open with an actively listening GRPC server.
func (*GrpcEndpoint) Open ¶
func (c *GrpcEndpoint) Open(ctx context.Context) (err error)
Open method are opens a connection using the parameters resolved by the referenced connection resolver and creates a GRPC server (controller) using the set options and parameters.
Parameters: - ctx context.Context a context to trace execution through call chain.
Retunrns: an error if one is raised.
func (*GrpcEndpoint) Register ¶
func (c *GrpcEndpoint) Register(registration IRegisterable)
Register method are registers a registerable object for dynamic endpoint discovery.
- registration the registration to add.
See IRegisterable
func (*GrpcEndpoint) RegisterCommandableMethod ¶
func (c *GrpcEndpoint) RegisterCommandableMethod(method string, schema *cvalid.Schema, action func(ctx context.Context, args *cexec.Parameters) (result any, err error))
RegisterCommandableMethod method are registers a commandable method in c objects GRPC server (controller) by the given name.
Parameters: - ctx context.Context a context to trace execution through call chain. - method the GRPC method name. - schema the schema to use for parameter validation. - action the action to perform at the given route.
func (*GrpcEndpoint) RegisterController ¶
func (c *GrpcEndpoint) RegisterController(sd *grpc.ServiceDesc, implementation any)
RegisterController method are registers a controller with related implementation
- implementation the service implementation method Invoke.
func (*GrpcEndpoint) SetReferences ¶
func (c *GrpcEndpoint) SetReferences(ctx context.Context, references cref.IReferences)
SetReferences method are sets references to c endpoint"s logger, counters, and connection resolver. References:
- logger: "*:logger:*:*:1.0"
- counters: "*:counters:*:*:1.0"
- discovery: "*:discovery:*:*:1.0" (for the connection resolver) Parameters:
- ctx context.Context operation context
- references an IReferences object, containing references to a logger, counters, and a connection resolver.
See IReferences (in the PipServices "Commons" package)
func (*GrpcEndpoint) Unregister ¶
func (c *GrpcEndpoint) Unregister(registration IRegisterable)
Unregister mwthod are unregisters a registerable object, so that it is no longer used in dynamic endpoint discovery.
- registration the registration to remove.
See IRegisterable
type IGrpcControllerOverrides ¶
type IGrpcControllerOverrides interface {
Register()
}
type IRegisterable ¶
type IRegisterable interface {
// Perform required registration steps.
Register()
}
IRegisterable is interface to perform on-demand registrations.
type InvokeComandMediator ¶
type InvokeComandMediator struct { InvokeFunc func(ctx context.Context, request *grpcproto.InvokeRequest) (response *grpcproto.InvokeReply, err error) grpcproto.CommandableServer }
InvokeComandMediator Helper class for implements invoke method in CommandableGrpc
func (*InvokeComandMediator) Invoke ¶
func (c *InvokeComandMediator) Invoke(ctx context.Context, request *grpcproto.InvokeRequest) (response *grpcproto.InvokeReply, err error)