Documentation
¶
Index ¶
- Constants
- type FabricError
- type FabricInitializableService
- type FabricService
- type FabricServiceCore
- type OnServerShutdownEnabled
- type OnServiceReadyEnabled
- type RESTBridgeConfig
- type RESTBridgeEnabled
- type RequestBuilder
- type RestServiceRequest
- type ServiceLifecycleHookEnabled
- type ServiceLifecycleManager
- type ServiceRegistry
- type SetupRESTBridgeRequest
Constants ¶
const ( LifecycleManagerChannelName = bus.RANCH_INTERNAL_CHANNEL_PREFIX + "service-lifecycle-manager" // store constants ServiceReadyStore = "service-ready-notification-store" ServiceInitStateChange = "service-init-state-change" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FabricError ¶
type FabricError struct { Type string `json:"type,omitempty"` Title string `json:"title"` Status int `json:"status"` Detail string `json:"detail"` Instance string `json:"instance,omitempty"` }
FabricError is a RFC7807 standard error properties (https://tools.ietf.org/html/rfc7807)
func GetFabricError ¶
func GetFabricError(message string, code int, detail string) FabricError
GetFabricError will return a structured, standardized Error object that is compliant with RFC7807 standard error properties (https://tools.ietf.org/html/rfc7807)
type FabricInitializableService ¶
type FabricInitializableService interface {
Init(core FabricServiceCore) error
}
FabricInitializableService Optional interface, if implemented by a fabric service, its Init method will be invoked when the service is registered in the ServiceRegistry.
type FabricService ¶
type FabricService interface { // Handles a single Fabric Request HandleServiceRequest(request *model.Request, core FabricServiceCore) }
FabricService Interface containing all APIs which should be implemented by Fabric Services.
type FabricServiceCore ¶
type FabricServiceCore interface { // Bus Returns the EventBus instance. Bus() bus.EventBus // SendResponse Uses the "responsePayload" and "request" params to build and send model.Response object // on the service channel. SendResponse(request *model.Request, responsePayload interface{}) // SendResponseAsString Uses the "responsePayload" and "request" params to build and send model.Response object // on the service channel. The payload is not marshalled to JSON, but sent as a string. SendResponseAsString(request *model.Request, responsePayload string) // SendResponseAsStringWithHeaders Uses the "responsePayload" and "request" params to build and send model.Response object // on the service channel. The payload is not marshalled to JSON, but sent as a string... also.. you know.. headers SendResponseAsStringWithHeaders(request *model.Request, responsePayload string, headers map[string]any) // SendResponseWithHeaders is the same as SendResponse, but include headers. Useful for HTTP REST interfaces - these headers will be // set as HTTP response headers. Great for custom mime-types, binary stuff and more. SendResponseWithHeaders(request *model.Request, responsePayload interface{}, headers map[string]any) // SendResponseWithHeadersAndCode is the same as SendResponseWithHeaders, but inclides a custom HTTP status code. SendResponseWithHeadersAndCode(request *model.Request, responsePayload interface{}, headers map[string]any, code int) // SendErrorResponse builds an error model.Response object and sends it on the service channel as response to the "request" param. SendErrorResponse(request *model.Request, responseErrorCode int, responseErrorMessage string) // SendErrorResponseWithPayload is the same as SendErrorResponse, but adds a payload SendErrorResponseWithPayload(request *model.Request, responseErrorCode int, responseErrorMessage string, payload interface{}) // SendErrorResponseWithHeaders is the same as SendErrorResponse, but adds headers as well. SendErrorResponseWithHeaders(request *model.Request, responseErrorCode int, responseErrorMessage string, headers map[string]any) // SendErrorResponseAsStringWithHeadersAndPayload is the same as SendErrorResponseWithPayload, but adds headers as well. SendErrorResponseAsStringWithHeadersAndPayload(request *model.Request, responseErrorCode int, responseErrorMessage string, payload string, headers map[string]any) // SendErrorResponseWithHeadersAndPayload is the same as SendErrorResponseWithPayload, but adds headers as well. SendErrorResponseWithHeadersAndPayload(request *model.Request, responseErrorCode int, responseErrorMessage string, payload interface{}, headers map[string]any) // HandleUnknownRequest handles unknown/unsupported/un-implemented requests, HandleUnknownRequest(request *model.Request) // RestServiceRequest will make a new RestService call. RestServiceRequest(restRequest *RestServiceRequest, successHandler model.ResponseHandlerFunction, errorHandler model.ResponseHandlerFunction) // SetHeaders Set global headers for a given fabric service (each service has its own set of global headers). // The headers will be applied to all requests made by this instance's RestServiceRequest method. // Global header values can be overridden per request via the RestServiceRequest.Headers property. SetHeaders(headers map[string]string) // GenerateJSONHeaders Automatically ready to go map with json headers. GenerateJSONHeaders() map[string]string // SetDefaultJSONHeaders Automatically sets default accept and return content types as 'application/json' SetDefaultJSONHeaders() }
FabricServiceCore is the interface providing base functionality to fabric services.
type OnServerShutdownEnabled ¶ added in v0.1.0
type OnServerShutdownEnabled interface {
OnServerShutdown() // teardown logic goes here and will be automatically invoked on graceful server shutdown
}
type OnServiceReadyEnabled ¶ added in v0.1.0
type OnServiceReadyEnabled interface {
OnServiceReady() chan bool // service initialization logic should be implemented here
}
type RESTBridgeConfig ¶
type RESTBridgeConfig struct { ServiceChannel string // transport service channel Uri string // URI to map the transport service to Method string // HTTP verb to map the transport service request to URI with AllowHead bool // whether HEAD calls are allowed for this bridge point AllowOptions bool // whether OPTIONS calls are allowed for this bridge point FabricRequestBuilder RequestBuilder // function to transform HTTP request into a transport request }
type RESTBridgeEnabled ¶ added in v0.1.0
type RESTBridgeEnabled interface {
GetRESTBridgeConfig() []*RESTBridgeConfig // service-to-REST endpoint mappings go here
}
type RequestBuilder ¶
type RestServiceRequest ¶
type RestServiceRequest struct { // The destination URL of the request. Uri string `json:"uri"` // HTTP Method to use, e.g. GET, POST, PATCH etc. Method string `json:"method"` // The body of the request. String and []byte payloads will be sent as is, // all other payloads will be serialized as json. Body interface{} `json:"body"` // HTTP headers of the request. Headers map[string]string `json:"headers"` // Optional type of the response body. If provided the service will try to deserialize // the response to this type. // If omitted the response body will be deserialized as map[string]interface{} // Note that if the response body is not a valid json you should set // the ResponseType to string or []byte otherwise you might get deserialization error // or empty result. ResponseType reflect.Type // Shouldn't be populated directly, the field is used to deserialize // com.vmware.bifrost.core.model.RestServiceRequest Java/Typescript requests ApiClass string `json:"apiClass"` }
type ServiceLifecycleHookEnabled ¶
type ServiceLifecycleHookEnabled interface { OnServiceReady() chan bool // service initialization logic should be implemented here OnServerShutdown() // teardown logic goes here and will be automatically invoked on graceful server shutdown GetRESTBridgeConfig() []*RESTBridgeConfig // service-to-REST endpoint mappings go here }
type ServiceLifecycleManager ¶
type ServiceLifecycleManager interface { //GetServiceHooks(serviceChannelName string) ServiceLifecycleHookEnabled GetOnReadyCapableService(serviceChannelName string) OnServiceReadyEnabled GetOnServerShutdownService(serviceChannelName string) OnServerShutdownEnabled GetRESTBridgeEnabledService(serviceChannelName string) RESTBridgeEnabled OverrideRESTBridgeConfig(serviceChannelName string, config []*RESTBridgeConfig) error }
func GetServiceLifecycleManager ¶
func GetServiceLifecycleManager() ServiceLifecycleManager
GetServiceLifecycleManager returns a singleton instance of ServiceLifecycleManager
type ServiceRegistry ¶
type ServiceRegistry interface { // GetAllServiceChannels returns all active Fabric service channels as a slice of strings GetAllServiceChannels() []string // RegisterService registers a new fabric service and associates it with a given EventBus channel. // Only one fabric service can be associated with a given channel. // If the fabric service implements the FabricInitializableService interface // its Init method will be called during the registration process. RegisterService(service FabricService, serviceChannelName string) error // UnregisterService unregisters the fabric service associated with the given channel. UnregisterService(serviceChannelName string) error // SetGlobalRestServiceBaseHost sets the global base host or host:port to be used by the restService SetGlobalRestServiceBaseHost(host string) // GetService returns the FabricService for the channel name given as the parameter GetService(serviceChannelName string) (FabricService, error) }
ServiceRegistry is the registry for all local fabric services.
func GetServiceRegistry ¶
func GetServiceRegistry() ServiceRegistry
func ResetServiceRegistry ¶
func ResetServiceRegistry() ServiceRegistry
ResetServiceRegistry destroys existing service registry instance and creates a new one
type SetupRESTBridgeRequest ¶
type SetupRESTBridgeRequest struct { ServiceChannel string Override bool Config []*RESTBridgeConfig }