Documentation
¶
Index ¶
- Constants
- Variables
- type AboutOperations
- func (c *AboutOperations) About(res http.ResponseWriter, req *http.Request)
- func (c *AboutOperations) GetAboutOperation() func(res http.ResponseWriter, req *http.Request)
- func (c *AboutOperations) GetNetworkAddresses() []string
- func (c *AboutOperations) SetReferences(ctx context.Context, references crefer.IReferences)
- type CommandableHttpController
- type CommandableSwaggerDocument
- type HeartbeatOperations
- type HeartbeatRestController
- type HttpEndpoint
- func (c *HttpEndpoint) AddCorsHeader(header string, origin string)
- func (c *HttpEndpoint) Close(ctx context.Context) error
- func (c *HttpEndpoint) Configure(ctx context.Context, config *cconf.ConfigParams)
- func (c *HttpEndpoint) GetTraceId(req *http.Request) string
- func (c *HttpEndpoint) IsOpen() bool
- func (c *HttpEndpoint) Open(ctx context.Context) error
- func (c *HttpEndpoint) Register(registration IRegisterable)
- func (c *HttpEndpoint) RegisterInterceptor(route string, ...)
- func (c *HttpEndpoint) RegisterRoute(method string, route string, schema *cvalid.Schema, action http.HandlerFunc)
- func (c *HttpEndpoint) RegisterRouteWithAuth(method string, route string, schema *cvalid.Schema, ...)
- func (c *HttpEndpoint) SetReferences(ctx context.Context, references crefer.IReferences)
- func (c *HttpEndpoint) Unregister(registration IRegisterable)
- type IRegisterable
- type ISchemaBaseWithValueType
- type ISchemaWithProperties
- type ISwaggerController
- type RestController
- func (c *RestController) Close(ctx context.Context) error
- func (c *RestController) Configure(ctx context.Context, config *cconf.ConfigParams)
- func (c *RestController) DecodeBody(req *http.Request, target any) error
- func (c *RestController) GetFilterParams(req *http.Request) *cquery.FilterParams
- func (c *RestController) GetPagingParams(req *http.Request) *cquery.PagingParams
- func (c *RestController) GetParam(req *http.Request, name string) string
- func (c *RestController) GetTraceId(req *http.Request) string
- func (c *RestController) Instrument(ctx context.Context, name string) *trace.InstrumentTiming
- func (c *RestController) InstrumentError(ctx context.Context, name string, errIn error, resIn any) (result any, err error)
- func (c *RestController) IsOpen() bool
- func (c *RestController) Open(ctx context.Context) error
- func (c *RestController) Register()
- func (c *RestController) RegisterInterceptor(route string, ...)
- func (c *RestController) RegisterOpenApiSpec(content string)
- func (c *RestController) RegisterOpenApiSpecFromFile(path string)
- func (c *RestController) RegisterRoute(method string, route string, schema *cvalid.Schema, ...)
- func (c *RestController) RegisterRouteWithAuth(method string, route string, schema *cvalid.Schema, ...)
- func (c *RestController) SendCreatedResult(res http.ResponseWriter, req *http.Request, result any, err error)
- func (c *RestController) SendDeletedResult(res http.ResponseWriter, req *http.Request, result any, err error)
- func (c *RestController) SendError(res http.ResponseWriter, req *http.Request, err error)
- func (c *RestController) SendResult(res http.ResponseWriter, req *http.Request, result any, err error)
- func (c *RestController) SetReferences(ctx context.Context, references crefer.IReferences)
- func (c *RestController) UnsetReferences()
- type RestOperations
- func (c *RestOperations) Configure(ctx context.Context, config *cconf.ConfigParams)
- func (c *RestOperations) DecodeBody(req *http.Request, target any) error
- func (c *RestOperations) GetFilterParams(req *http.Request) *cquery.FilterParams
- func (c *RestOperations) GetPagingParams(req *http.Request) *cquery.PagingParams
- func (c *RestOperations) GetParam(req *http.Request, name string) string
- func (c *RestOperations) GetTraceId(req *http.Request) string
- func (c *RestOperations) SendBadRequest(res http.ResponseWriter, req *http.Request, message string)
- func (c *RestOperations) SendConflict(res http.ResponseWriter, req *http.Request, message string)
- func (c *RestOperations) SendCreatedResult(res http.ResponseWriter, req *http.Request, result any, err error)
- func (c *RestOperations) SendDeletedResult(res http.ResponseWriter, req *http.Request, result any, err error)
- func (c *RestOperations) SendEmptyResult(res http.ResponseWriter, req *http.Request, err error)
- func (c *RestOperations) SendError(res http.ResponseWriter, req *http.Request, err error)
- func (c *RestOperations) SendInternalError(res http.ResponseWriter, req *http.Request, message string)
- func (c *RestOperations) SendNotFound(res http.ResponseWriter, req *http.Request, message string)
- func (c *RestOperations) SendResult(res http.ResponseWriter, req *http.Request, result any, err error)
- func (c *RestOperations) SendServerUnavailable(res http.ResponseWriter, req *http.Request, message string)
- func (c *RestOperations) SendSessionExpired(res http.ResponseWriter, req *http.Request, message string)
- func (c *RestOperations) SendUnauthorized(res http.ResponseWriter, req *http.Request, message string)
- func (c *RestOperations) SetReferences(ctx context.Context, references crefer.IReferences)
- type StatusOperations
- type StatusRestController
Constants ¶
const ( DefaultConnectionTimeout = "60000" DefaultFileMaxSize = 200 * 1024 * 1024 DefaultRequestMaxSize = 1024 * 1024 )
Variables ¶
var HttpRequestDetector = _THttpRequestDetector{}
HttpRequestDetector helper class that retrieves parameters from HTTP requests.
var HttpResponseSender = _THttpResponseSender{}
HttpResponseSender helper class that handles HTTP-based responses.
Functions ¶
This section is empty.
Types ¶
type AboutOperations ¶
type AboutOperations struct { *RestOperations // contains filtered or unexported fields }
func NewAboutOperations ¶
func NewAboutOperations() *AboutOperations
func (*AboutOperations) About ¶
func (c *AboutOperations) About(res http.ResponseWriter, req *http.Request)
func (*AboutOperations) GetAboutOperation ¶
func (c *AboutOperations) GetAboutOperation() func(res http.ResponseWriter, req *http.Request)
func (*AboutOperations) GetNetworkAddresses ¶
func (c *AboutOperations) GetNetworkAddresses() []string
func (*AboutOperations) SetReferences ¶
func (c *AboutOperations) SetReferences(ctx context.Context, references crefer.IReferences)
type CommandableHttpController ¶
type CommandableHttpController struct { *RestController SwaggerAuto bool // contains filtered or unexported fields }
CommandableHttpController abstract service that receives remove calls via HTTP/REST protocol to operations automatically generated for commands defined in ICommandable components. Each command is exposed as POST operation that receives all parameters in body object.
Commandable services require only 3 lines of code to implement a robust external HTTP-based remote interface.
Configuration parameters: - base_route: base route for remote URI - dependencies: - endpoint: override for HTTP Endpoint dependency - controller: override for Controller dependency - connection(s): - discovery_key: (optional) a key to retrieve the connection from 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 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 - *:endpoint:http:*:1.0 (optional) HttpEndpoint reference see clients.CommandableHttpClient see RestController Example: type MyCommandableHttpController struct { *CommandableHttpController } func NewMyCommandableHttpController() *MyCommandableHttpController { c := MyCommandableHttpController{ CommandableHttpController: controllers.NewCommandableHttpController("dummies"), } c.DependencyResolver.Put(context.Background(), "service", cref.NewDescriptor("pip-services-dummies", "service", "default", "*", "*")) return &c } controller := NewMyCommandableHttpController(); controller.Configure(context.Background(), cconf.NewConfigParamsFromTuples( "connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080, )); controller.SetReferences(context.Background(), cref.NewReferencesFromTuples( cref.NewDescriptor("mygroup","service","default","default","1.0"), service )); opnErr := controller.Open(context.Background(), "123") if opnErr == nil { fmt.Println("The REST controller is running on port 8080"); }
func InheritCommandableHttpController ¶
func InheritCommandableHttpController(overrides IRegisterable, baseRoute string) *CommandableHttpController
InheritCommandableHttpController creates a new instance of the controller.
Parameters: - overrides references to child class that overrides virtual methods - baseRoute string a service base route. Returns: *CommandableHttpController pointer on new instance CommandableHttpController
func (*CommandableHttpController) Configure ¶
func (c *CommandableHttpController) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure method configures component by passing configuration parameters.
Parameters: - ctx context.Context - config configuration parameters to be set.
func (*CommandableHttpController) Register ¶
func (c *CommandableHttpController) Register()
Register method are registers all service routes in HTTP endpoint.
type CommandableSwaggerDocument ¶
type CommandableSwaggerDocument struct { Commands []ccomands.ICommand Version string BaseRoute string InfoTitle string InfoDescription string InfoVersion string InfoTermsOfService string InfoContactName string InfoContactUrl string InfoContactEmail string InfoLicenseName string InfoLicenseUrl string // contains filtered or unexported fields }
func NewCommandableSwaggerDocument ¶
func NewCommandableSwaggerDocument(baseRoute string, config *cconf.ConfigParams, commands []ccomands.ICommand) *CommandableSwaggerDocument
func (*CommandableSwaggerDocument) GetSpaces ¶
func (c *CommandableSwaggerDocument) GetSpaces(length int) string
func (*CommandableSwaggerDocument) ToString ¶
func (c *CommandableSwaggerDocument) ToString() string
func (*CommandableSwaggerDocument) WriteData ¶
func (c *CommandableSwaggerDocument) WriteData(indent int, data map[string]any)
func (*CommandableSwaggerDocument) WriteName ¶
func (c *CommandableSwaggerDocument) WriteName(indent int, name string)
type HeartbeatOperations ¶
type HeartbeatOperations struct {
*RestOperations
}
func NewHeartbeatOperations ¶
func NewHeartbeatOperations() *HeartbeatOperations
NewHeartbeatOperations creates new instance HeartbeatOperations
Returns: *HeartbeatOperations
func (*HeartbeatOperations) GetHeartbeatOperation ¶
func (c *HeartbeatOperations) GetHeartbeatOperation() func(res http.ResponseWriter, req *http.Request)
GetHeartbeatOperation is a heartbeat method are insert timestamp into HTTP result
func (*HeartbeatOperations) Heartbeat ¶
func (c *HeartbeatOperations) Heartbeat(res http.ResponseWriter, req *http.Request)
Heartbeat method are insert timestamp into HTTP result
type HeartbeatRestController ¶
type HeartbeatRestController struct { *RestController // contains filtered or unexported fields }
HeartbeatRestController service returns heartbeat via HTTP/REST protocol. The service responds on /heartbeat route (can be changed) with a string with the current time in UTC. This service route can be used to health checks by load-balancers and container orchestrators.
Configuration parameters: - baseroute: base route for remote URI (default: "") - route: route to heartbeat operation (default: "heartbeat") - dependencies: - endpoint: override for HTTP Endpoint dependency - connection(s): - discovery_key: (optional) a key to retrieve the connection from 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 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 - *:endpoint:http:*:1.0 (optional) HttpEndpoint reference see RestController see clients.RestClient Example: controller := NewHeartbeatController(); controller.Configure(context.Background(), cconf.NewConfigParamsFromTuples( "route", "ping", "connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080, )); opnErr := controller.Open(context.Background()) if opnErr == nil { fmt.Println("The Heartbeat controller is accessible at http://+:8080/ping"); }
func NewHeartbeatRestController ¶
func NewHeartbeatRestController() *HeartbeatRestController
NewHeartbeatRestController creates a new instance of c service.
func (*HeartbeatRestController) Configure ¶
func (c *HeartbeatRestController) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure component by passing configuration parameters.
Parameters: - ctx context.Context - config configuration parameters to be set.
func (*HeartbeatRestController) Register ¶
func (c *HeartbeatRestController) Register()
Register all service routes in HTTP endpoint.
type HttpEndpoint ¶
type HttpEndpoint struct {
// contains filtered or unexported fields
}
HttpEndpoint used for creating HTTP endpoints. An endpoint is a URL, at which a given service can be accessed by a client.
Configuration parameters: Parameters to pass to the configure method for component configuration: - cors_headers - a comma-separated list of allowed CORS headers - cors_origins - a comma-separated list of allowed CORS origins - connection(s) - the connection resolver"s connections: - "connection.discovery_key" - the key to use for connection resolving in a discovery service; - "connection.protocol" - the connection"s protocol; - "connection.host" - the target host; - "connection.port" - the target port; - "connection.uri" - the target URI. - credential - the HTTPS credentials: - "credential.ssl_key_file" - the SSL func (c *HttpEndpoint )key in PEM - "credential.ssl_crt_file" - the SSL certificate in PEM - "credential.ssl_ca_file" - the certificate authorities (root cerfiticates) in PEM References: A logger, counters, and a connection resolver can be referenced by passing the following references to the object"s setReferences method: - logger: "*:logger:*:*:1.0"; - counters: "*:counters:*:*:1.0"; - discovery: "*:discovery:*:*:1.0" (for the connection resolver). Examples: endpoint := NewHttpEndpoint(); endpoint.Configure(context.Background(), config); endpoint.SetReferences(context.Background(), references); ... endpoint.Open(context.Background())
func NewHttpEndpoint ¶
func NewHttpEndpoint() *HttpEndpoint
NewHttpEndpoint creates new HttpEndpoint
func (*HttpEndpoint) AddCorsHeader ¶
func (c *HttpEndpoint) AddCorsHeader(header string, origin string)
AddCorsHeader method adds allowed header, ignore if it already exists must be called before to opening endpoint
func (*HttpEndpoint) Close ¶
func (c *HttpEndpoint) Close(ctx context.Context) error
Close method are closes this endpoint and the REST server (service) that was opened earlier.
Parameters: - ctx context.Context execution context to trace execution through call chain. Returns: error an error if one is raised.
func (*HttpEndpoint) Configure ¶
func (c *HttpEndpoint) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure method are configures this 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 service; - "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 func (c *HttpEndpoint )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 - config configuration parameters, containing a "connection(s)" section.
func (*HttpEndpoint) GetTraceId ¶
func (c *HttpEndpoint) GetTraceId(req *http.Request) string
GetTraceId method returns traceId from request
Parameters: - req *http.Request request Returns: string trace_id or empty string
func (*HttpEndpoint) IsOpen ¶
func (c *HttpEndpoint) IsOpen() bool
IsOpen method is whether this endpoint is open with an actively listening REST server.
func (*HttpEndpoint) Open ¶
func (c *HttpEndpoint) Open(ctx context.Context) error
Open a connection using the parameters resolved by the referenced connection resolver and creates a REST server (service) using the set options and parameters.
Parameters: - ctx context.Context execution context to trace execution through call chain. Returns: error an error if one is raised.
func (*HttpEndpoint) Register ¶
func (c *HttpEndpoint) Register(registration IRegisterable)
Register a registrable object for dynamic endpoint discovery.
Parameters: - registration IRegisterable implements of IRegisterable interface. See IRegisterable
func (*HttpEndpoint) RegisterInterceptor ¶
func (c *HttpEndpoint) RegisterInterceptor(route string, action func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc))
RegisterInterceptor method are registers a middleware action for the given route. Parameters:
- route the route to register in this object"s REST server (service).
- action the middleware action to perform at the given route.
func (*HttpEndpoint) RegisterRoute ¶
func (c *HttpEndpoint) RegisterRoute(method string, route string, schema *cvalid.Schema, action http.HandlerFunc)
RegisterRoute method are registers an action in this objects REST server (service) by the given method and route.
Parameters: - method string the HTTP method of the route. - route string the route to register in this object"s REST server (service). - schema *cvalid.Schema the schema to use for parameter validation. - action http.HandlerFunc the action to perform at the given route.
func (*HttpEndpoint) RegisterRouteWithAuth ¶
func (c *HttpEndpoint) RegisterRouteWithAuth(method string, route string, schema *cvalid.Schema, authorize func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc), action http.HandlerFunc)
RegisterRouteWithAuth method are registers an action with authorization in this objects REST server (service) by the given method and route. Parameters:
- method string the HTTP method of the route.
- route string the route to register in this object"s REST server (service).
- schema *cvalid.Schema the schema to use for parameter validation.
- authorize the authorization interceptor
- action the action to perform at the given route.
func (*HttpEndpoint) SetReferences ¶
func (c *HttpEndpoint) SetReferences(ctx context.Context, references crefer.IReferences)
SetReferences method are sets references to this 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: - references an IReferences object, containing references to a logger, counters, and a connection resolver.
func (*HttpEndpoint) Unregister ¶
func (c *HttpEndpoint) Unregister(registration IRegisterable)
Unregister a registerable object, so that it is no longer used in dynamic endpoint discovery.
Parameters: - registration IRegisterable the registration to remove. See IRegisterable
type IRegisterable ¶
type IRegisterable interface {
// Register perform required registration steps.
Register()
}
IRegisterable is interface to perform on-demand registrations.
type ISchemaBaseWithValueType ¶
type ISchemaBaseWithValueType interface { cvalid.ISchemaBase ValueType() any }
type ISchemaWithProperties ¶
type ISchemaWithProperties interface { cvalid.ISchema Properties() []*cvalid.PropertySchema }
type ISwaggerController ¶
type ISwaggerController interface { // RegisterOpenApiSpec Perform required Swagger registration steps. RegisterOpenApiSpec(baseRoute string, swaggerRoute string) }
ISwaggerController Interface to perform Swagger registrations.
type RestController ¶
type RestController struct { Overrides IRegisterable //The base route. BaseRoute string //The HTTP endpoint that exposes this service. Endpoint *HttpEndpoint //The dependency resolver. DependencyResolver *crefer.DependencyResolver //The logger. Logger *clog.CompositeLogger //The performance counters. Counters *ccount.CompositeCounters // The tracer. Tracer *ctrace.CompositeTracer SwaggerController ISwaggerController SwaggerEnabled bool SwaggerRoute string // contains filtered or unexported fields }
RestController Abstract service that receives remove calls via HTTP/REST protocol.
Configuration parameters: - base_route: base route for remote URI - dependencies: - endpoint: override for HTTP Endpoint dependency - controller: override for Controller dependency - connection(s): - discovery_key: (optional) a key to retrieve the connection from 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 services to resolve connection - *:endpoint:http:*:1.0 (optional) HttpEndpoint reference See clients.RestClient Example: type MyRestController struct { *RestController service IMyService } ... func NewMyRestController() *MyRestController { c := MyRestController{} c.RestController = services.NewRestController() c.RestController.IRegisterable = &c c.numberOfCalls = 0 c.DependencyResolver.Put(context.Background(), "service", crefer.NewDescriptor("mygroup", "service", "*", "*", "1.0")) return &c } func (c * MyRestController) SetReferences(ctx context.Context, references IReferences) { c.RestController.SetReferences(ctx, references); resolv := c.DependencyResolver.GetRequired("service"); if resolv != nil { c.service, _ = resolv.(IMyService) } } func (c *MyRestController) getOneById(res http.ResponseWriter, req *http.Request) { params := req.URL.Query() vars := mux.Vars(req) mydataId := params.Get("mydata_id") if mydataId == "" { mydataId = vars["mydatay_id"] } result, err := c.controller.GetOneById(params.Get("tace_id"), mydataId), c.SendResult(res, req, result, err) } func (c * MyRestController) Register() { c.RegisterRoute( "get", "get_mydata/{mydata_id}", &cvalid.NewObjectSchema(). WithRequiredProperty("mydata_id", cconv.String).Schema, c.getOneById, ) ... } controller := NewMyRestController(); controller.Configure(context.Background(), cconf.NewConfigParamsFromTuples( "connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080, )); controller.SetReferences(context.Background(), cref.NewReferencesFromTuples( cref.NewDescriptor("mygroup","service","default","default","1.0"), service )); opnRes := controller.Open(context.Background(), "123") if opnErr == nil { fmt.Println("The REST cntroller is running on port 8080"); }
func InheritRestController ¶
func InheritRestController(overrides IRegisterable) *RestController
InheritRestController creates new instance of RestController
func (*RestController) Close ¶
func (c *RestController) Close(ctx context.Context) error
Close method are closes component and frees used resources.
Parameters: - ctx context.Context execution context to trace execution through call chain. Returns: error or nil no errors occurred.
func (*RestController) Configure ¶
func (c *RestController) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure method are configures component by passing configuration parameters.
Parameters: - ctx context.Context - config *cconf.ConfigParams configuration parameters to be set.
func (*RestController) DecodeBody ¶
func (c *RestController) DecodeBody(req *http.Request, target any) error
DecodeBody methods helps decode body
Parameters: - req - incoming request - target - pointer on target variable for decode
Returns error
func (*RestController) GetFilterParams ¶
func (c *RestController) GetFilterParams(req *http.Request) *cquery.FilterParams
GetFilterParams methods helps decode filter params
Parameters: - req incoming request Returns: filter params
func (*RestController) GetPagingParams ¶
func (c *RestController) GetPagingParams(req *http.Request) *cquery.PagingParams
GetPagingParams methods helps decode paging params
Parameters: - req incoming request Returns: paging params
func (*RestController) GetParam ¶
func (c *RestController) GetParam(req *http.Request, name string) string
GetParam methods helps get all params from query
Parameters: - req incoming request - name parameter name Returns value or empty string if param not exists
func (*RestController) GetTraceId ¶
func (c *RestController) GetTraceId(req *http.Request) string
GetTraceId method returns TraceId from request
Parameters: - req *http.Request request Returns: string trace_id or empty string
func (*RestController) Instrument ¶
func (c *RestController) Instrument(ctx context.Context, name string) *trace.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 execution context to trace execution through call chain. - name a method name. Returns: Timing object to end the time measurement.
func (*RestController) InstrumentError ¶
func (c *RestController) InstrumentError(ctx context.Context, name string, errIn error, resIn any) (result any, err error)
InstrumentError method are adds instrumentation to error handling.
Parameters: - ctx context.Context execution context to trace execution through call chain. - name string a method name. - err error an occurred error - result any (optional) an execution result Returns: result any, err error (optional) an execution callback
func (*RestController) IsOpen ¶
func (c *RestController) IsOpen() bool
IsOpen method checks if the component is opened.
Returns: true if the component has been opened and false otherwise.
func (*RestController) Open ¶
func (c *RestController) Open(ctx context.Context) error
Open method are opens the component.
Parameters: - ctx context.Context execution context to trace execution through call chain. Returns: error or nil no errors occured.
func (*RestController) Register ¶
func (c *RestController) Register()
Register method are registers all service routes in HTTP endpoint.
func (*RestController) RegisterInterceptor ¶
func (c *RestController) RegisterInterceptor(route string, action func(res http.ResponseWriter, req *http.Request, next http.HandlerFunc))
RegisterInterceptor method are registers a middleware for a given route in HTTP endpoint.
Parameters: - route a command route. Base route will be added to this route - action an action function that is called when middleware is invoked.
func (*RestController) RegisterOpenApiSpec ¶
func (c *RestController) RegisterOpenApiSpec(content string)
func (*RestController) RegisterOpenApiSpecFromFile ¶
func (c *RestController) RegisterOpenApiSpecFromFile(path string)
func (*RestController) RegisterRoute ¶
func (c *RestController) RegisterRoute(method string, route string, schema *cvalid.Schema, action func(res http.ResponseWriter, req *http.Request))
RegisterRoute method are registers a route in HTTP endpoint.
Parameters: - method HTTP method: "get", "head", "post", "put", "delete" - route a command route. Base route will be added to this route - schema a validation schema to validate received parameters. - action an action function that is called when operation is invoked.
func (*RestController) RegisterRouteWithAuth ¶
func (c *RestController) RegisterRouteWithAuth(method string, route string, schema *cvalid.Schema, authorize func(res http.ResponseWriter, req *http.Request, next http.HandlerFunc), action func(res http.ResponseWriter, req *http.Request))
RegisterRouteWithAuth method are registers a route with authorization in HTTP endpoint.
Parameters: - method HTTP method: "get", "head", "post", "put", "delete" - route a command route. Base route will be added to this route - schema a validation schema to validate received parameters. - authorize an authorization interceptor - action an action function that is called when operation is invoked.
func (*RestController) SendCreatedResult ¶
func (c *RestController) SendCreatedResult(res http.ResponseWriter, req *http.Request, result any, err error)
SendCreatedResult method are sends newly created object as JSON. That callback function call be called directly or passed as a parameter to business logic components. If object is not nil it returns 201 status code. For nil results it returns 204 status code. If error occur it sends ErrorDescription with approproate status code.
Parameters: - req a HTTP request object. - res a HTTP response object. - result (optional) result object to send - err error (optional) error objrct to send
func (*RestController) SendDeletedResult ¶
func (c *RestController) SendDeletedResult(res http.ResponseWriter, req *http.Request, result any, err error)
SendDeletedResult method are sends deleted object as JSON. That callback function call be called directly or passed as a parameter to business logic components. If object is not nil it returns 200 status code. For nil results it returns 204 status code. If error occur it sends ErrorDescription with appropriate status code.
Parameters: - req a HTTP request object. - res a HTTP response object. - result (optional) result object to send - err error (optional) error objrct to send
func (*RestController) SendError ¶
func (c *RestController) SendError(res http.ResponseWriter, req *http.Request, err error)
SendError method are sends error serialized as ErrorDescription object and appropriate HTTP status code. If status code is not defined, it uses 500 status code.
Parameters: - req a HTTP request object. - res a HTTP response object. - error an error object to be sent.
func (*RestController) SendResult ¶
func (c *RestController) SendResult(res http.ResponseWriter, req *http.Request, result any, err error)
SendResult method are sends result as JSON object. That function call be called directly or passed as a parameter to business logic components. If object is not nil it returns 200 status code. For nil results it returns 204 status code. If error occur it sends ErrorDescription with approproate status code.
Parameters: - req a HTTP request object. - res a HTTP response object. - result (optional) result object to send - err error (optional) error objrct to send
func (*RestController) SetReferences ¶
func (c *RestController) SetReferences(ctx context.Context, references crefer.IReferences)
SetReferences method are sets references to dependent components.
Parameters: - ctx context.Context - references crefer.IReferences references to locate the component dependencies.
func (*RestController) UnsetReferences ¶
func (c *RestController) UnsetReferences()
UnsetReferences method are unsets (clears) previously set references to dependent components.
type RestOperations ¶
type RestOperations struct { Logger *clog.CompositeLogger Counters *ccount.CompositeCounters DependencyResolver *crefer.DependencyResolver }
RestOperations helper class for REST operations
func NewRestOperations ¶
func NewRestOperations() *RestOperations
NewRestOperations creates new instance of RestOperations
func (*RestOperations) Configure ¶
func (c *RestOperations) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure method are configures this RestOperations using the given configuration parameters.
Parameters: - ctx context.Context - config *cconf.ConfigParams confif parameters
func (*RestOperations) DecodeBody ¶
func (c *RestOperations) DecodeBody(req *http.Request, target any) error
DecodeBody methods helps decode body
Parameters: - req incoming request - target pointer on target variable for decode
Returns: error
func (*RestOperations) GetFilterParams ¶
func (c *RestOperations) GetFilterParams(req *http.Request) *cquery.FilterParams
GetFilterParams method reruns filter params object from request
Parameters: - req *http.Request request Returns: *cdata.FilterParams filter params object
func (*RestOperations) GetPagingParams ¶
func (c *RestOperations) GetPagingParams(req *http.Request) *cquery.PagingParams
GetPagingParams method reruns paging params object from request
Parameters: - req *http.Request request Returns: *cdata.PagingParams pagings params object
func (*RestOperations) GetParam ¶
func (c *RestOperations) GetParam(req *http.Request, name string) string
GetParam methods helps get all params from query
Parameters: - req incoming request - name parameter name
Returns: value or empty string if param not exists
func (*RestOperations) GetTraceId ¶
func (c *RestOperations) GetTraceId(req *http.Request) string
GetTraceId method returns traceId from request
Parameters: - req *http.Request request Returns: string trace_id or empty string
func (*RestOperations) SendBadRequest ¶
func (c *RestOperations) SendBadRequest(res http.ResponseWriter, req *http.Request, message string)
func (*RestOperations) SendConflict ¶
func (c *RestOperations) SendConflict(res http.ResponseWriter, req *http.Request, message string)
func (*RestOperations) SendCreatedResult ¶
func (c *RestOperations) SendCreatedResult(res http.ResponseWriter, req *http.Request, result any, err error)
func (*RestOperations) SendDeletedResult ¶
func (c *RestOperations) SendDeletedResult(res http.ResponseWriter, req *http.Request, result any, err error)
func (*RestOperations) SendEmptyResult ¶
func (c *RestOperations) SendEmptyResult(res http.ResponseWriter, req *http.Request, err error)
func (*RestOperations) SendError ¶
func (c *RestOperations) SendError(res http.ResponseWriter, req *http.Request, err error)
func (*RestOperations) SendInternalError ¶
func (c *RestOperations) SendInternalError(res http.ResponseWriter, req *http.Request, message string)
func (*RestOperations) SendNotFound ¶
func (c *RestOperations) SendNotFound(res http.ResponseWriter, req *http.Request, message string)
func (*RestOperations) SendResult ¶
func (c *RestOperations) SendResult(res http.ResponseWriter, req *http.Request, result any, err error)
func (*RestOperations) SendServerUnavailable ¶
func (c *RestOperations) SendServerUnavailable(res http.ResponseWriter, req *http.Request, message string)
func (*RestOperations) SendSessionExpired ¶
func (c *RestOperations) SendSessionExpired(res http.ResponseWriter, req *http.Request, message string)
func (*RestOperations) SendUnauthorized ¶
func (c *RestOperations) SendUnauthorized(res http.ResponseWriter, req *http.Request, message string)
func (*RestOperations) SetReferences ¶
func (c *RestOperations) SetReferences(ctx context.Context, references crefer.IReferences)
SetReferences method are sets references to this RestOperations logger, counters, and connection resolver.
Parameters: - ctx context.Context - references an IReferences object, containing references to a logger, counters, and a dependency resolver.
type StatusOperations ¶
type StatusOperations struct { *RestOperations // contains filtered or unexported fields }
StatusOperations helper class for status service
func NewStatusOperations ¶
func NewStatusOperations() *StatusOperations
NewStatusOperations creates new instance of StatusOperations
func (*StatusOperations) GetStatusOperation ¶
func (c *StatusOperations) GetStatusOperation() func(res http.ResponseWriter, req *http.Request)
GetStatusOperation return function for get status
func (*StatusOperations) SetReferences ¶
func (c *StatusOperations) SetReferences(ctx context.Context, references crefer.IReferences)
SetReferences sets references to dependent components.
Parameters: - ctx context.Context - references crefer.IReferences references to locate the component dependencies.
func (*StatusOperations) Status ¶
func (c *StatusOperations) Status(res http.ResponseWriter, req *http.Request)
Status method handles status requests
Parameters: - req *http.Request an HTTP request - res http.ResponseWriter an HTTP response
type StatusRestController ¶
type StatusRestController struct { *RestController // contains filtered or unexported fields }
StatusRestController is a service that returns microservice status information via HTTP/REST protocol.
The service responds on /status route (can be changed) with a JSON object: { "id": unique container id (usually hostname) "name": container name (from ContextInfo) "description": container description (from ContextInfo) "start_time": time when container was started "current_time": current time in UTC "uptime": duration since container start time in milliseconds "properties": additional container properties (from ContextInfo) "components": descriptors of components registered in the container } Configuration parameters: - baseroute: base route for remote URI - route: status route (default: "status") - dependencies: - endpoint: override for HTTP Endpoint dependency - controller: override for Controller dependency - connection(s): - discovery_key: (optional) a key to retrieve the connection from 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 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 - *:endpoint:http:*:1.0 (optional) HttpEndpoint reference see: RestController see: clients.RestClient Example: service = NewStatusController(); service.Configure(context.Background(), cref.NewConfigParamsFromTuples( "connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080, )); opnErr:= service.Open(context.Background(), "123") if opnErr == nil { fmt.Println("The Status service is accessible at http://localhost:8080/status"); }
func NewStatusRestController ¶
func NewStatusRestController() *StatusRestController
NewStatusRestController method are creates a new instance of this service.
func (*StatusRestController) Configure ¶
func (c *StatusRestController) Configure(ctx context.Context, config *cconf.ConfigParams)
Configure method are configures component by passing configuration parameters.
Parameters: - ctx context.Context - config *cconf.ConfigParams configuration parameters to be set.
func (*StatusRestController) Register ¶
func (c *StatusRestController) Register()
Register method are registers all service routes in HTTP endpoint.
func (*StatusRestController) SetReferences ¶
func (c *StatusRestController) SetReferences(ctx context.Context, references crefer.IReferences)
SetReferences method are sets references to dependent components.
Parameters: - ctx context.Context - references crefer.IReferences references to locate the component dependencies.
Source Files
¶
- AboutOperations.go
- CommandableHttpController.go
- CommandableSwaggerDocument.go
- HeartbeatOperations.go
- HeartbeatRestController.go
- HttpEndpoint.go
- HttpRequestDetector.go
- HttpResponseSender.go
- IRegisterable.go
- ISwaggerController.go
- RestController.go
- RestOperations.go
- StatusOperations.go
- StatusRestController.go