service

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2022 License: BSD-2-Clause Imports: 13 Imported by: 6

Documentation

Index

Constants

View Source
const (
	LifecycleManagerChannelName = bus.TRANSPORT_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 added in v1.3.1

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 added in v1.3.1

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{})

	// 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]string)

	// 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]string)

	// SendErrorResponseWithHeadersAndPayload is the same as SendErrorResponseWithPayload, but adds headers as well.
	SendErrorResponseWithHeadersAndPayload(request *model.Request, responseErrorCode int, responseErrorMessage string, payload interface{}, headers map[string]string)

	// 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 RESTBridgeConfig added in v1.2.0

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 RequestBuilder added in v1.3.0

type RequestBuilder func(w http.ResponseWriter, r *http.Request) model.Request

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 added in v1.2.0

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 added in v1.2.0

type ServiceLifecycleManager interface {
	GetServiceHooks(serviceChannelName string) ServiceLifecycleHookEnabled
	OverrideRESTBridgeConfig(serviceChannelName string, config []*RESTBridgeConfig) error
}

func GetServiceLifecycleManager added in v1.2.0

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 added in v1.3.2

func ResetServiceRegistry() ServiceRegistry

ResetServiceRegistry destroys existing service registry instance and creates a new one

type SetupRESTBridgeRequest added in v1.2.0

type SetupRESTBridgeRequest struct {
	ServiceChannel string
	Override       bool
	Config         []*RESTBridgeConfig
}

Jump to

Keyboard shortcuts

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