Documentation ¶
Index ¶
- Constants
- type Context
- type Contract
- type DataHandlerConfig
- type DataType
- type Method
- type Payload
- type RequestHandler
- type Route
- type RouteContract
- type Service
- func (service *Service) AddRoute(route *Route)
- func (service *Service) SetupRoute(label string, endpoint RequestHandler, middlewares []fastalice.Constructor, ...) *Route
- func (service *Service) Start()
- func (service *Service) Status() *ServiceStatus
- func (service *Service) Stop() error
- func (service *Service) SubscribeToService(sub ServiceContract)
- type ServiceClient
- type ServiceContract
- type ServiceProvider
- type ServiceRequest
- type ServiceStatus
Constants ¶
const ( Binary DataType = 1 JSON = 2 Form = 3 )
const ( // DELETE defines the DELETE type of request DELETE Method = fasthttp.MethodDelete // GET defines the GET type of request GET = fasthttp.MethodGet // POST defines the POST type of request POST = fasthttp.MethodPost // PUT defines the PUT type of request PUT = fasthttp.MethodPut // Default values DefaultRouteMethod Method = GET DefaultBodyDataType = Binary // DefaultKey is the UserValue key used when no Key is passed to the initializer DefaultKey string = "data" )
const ( // Default Host is the host used if not initialized. DefaultHost string = "localhost" // Default Port is the port used if not initialized. DefaultPort = "8080" // Default Namespace is the namespace used if not initialized. DefaultNamespace = "" // Default Version is the version used if not initialized. DefaultVersion = "v0" // HTTP protocol HTTP protocol = "http" // HTTPS protocol HTTPS = "https" // RouteNotFoundError error when the service can't find a route RouteNotFoundError string = "route not found" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { *fasthttp.RequestCtx ServiceClients []ServiceClient }
func (*Context) ServiceClient ¶
func (ctx *Context) ServiceClient(sub ServiceContract) *ServiceClient
type Contract ¶
type Contract struct {
Services []ServiceContract
}
type DataHandlerConfig ¶
type RequestHandler ¶
type RequestHandler func(ctx *Context)
type Route ¶
type Route struct { *RouteContract // The endpoint is the path used to receive the request RequestHandler RequestHandler // Middlewares functions executed before the RequestHandler Middlewares []fastalice.Constructor // DataHandlers used to receive requests DataHandler fastalice.Constructor // contains filtered or unexported fields }
Route is the definition of a route and what's used to initialize a route
type RouteContract ¶
type RouteContract struct { // Label is an identification for the route. It's used on status and log information Label string // Description is a short text that helps to document the route Description string // Method is the fasthttp method the route will listen upon Method Method // Path is the location where the route will listen to Path string // DataHandlerConfig is the configuration for the route DataHandler. This is an optional field DataHandlerConfig DataHandlerConfig // Data is the Data used. Use an empty struct value Data interface{} }
RouteContract is the Contract description of a Route
func (*RouteContract) DataType ¶
func (route *RouteContract) DataType() DataType
type Service ¶
type Service struct { *ServiceContract // contains filtered or unexported fields }
Service is a Service Provider that starts itself and serves declared routes over a self created router
func (*Service) SetupRoute ¶
func (service *Service) SetupRoute( label string, endpoint RequestHandler, middlewares []fastalice.Constructor, dataHandler fastalice.Constructor, ) *Route
SetupRoute searches for a route contract identified by label, creates a Route, add to it the endpoint and the middlewares and put it on the Routes array returning the newly created routes
func (*Service) Start ¶
func (service *Service) Start()
* Start inits the main process executed by the service. It first creates the internal router and then start a listener for those routes and serve then on the specified Host, Port, Namespace and Version. For a Service created with the following values:
service := &Service { Label: "ExampleService", Description: "Just a server to cover route url building", Protocol: lotus.HTTP, Host: "myhost.com", Namespace: "example", }
func (*Service) Status ¶
func (service *Service) Status() *ServiceStatus
func (*Service) SubscribeToService ¶ added in v0.0.1
func (service *Service) SubscribeToService(sub ServiceContract)
type ServiceClient ¶
type ServiceClient struct {
*ServiceContract
}
func (*ServiceClient) SendRequest ¶
func (sc *ServiceClient) SendRequest(routeContract RouteContract, payload ServiceRequest) (*fasthttp.Response, error)
Sends a request and returns a response and an error. The response must be released
type ServiceContract ¶
type ServiceContract struct { // Name of the service. Used as a identifier for the service Label string // Description of the service. Intended to be a Short text describing the functionalities of the service Description string // Protocol is the protocol which the serve will use. The current options are: HTTP, HTTPS or TCP. Defaults to HTTP Protocol protocol // Host of the service. Can be an IPV4 or IPV6 address. Defaults to "localhost" Host string // Namespace of the service. The unique namespace which the service will be delivered upon. Defaults to "/" Namespace string // Port of the service listener Port int // A version identifier for the service. Defaults to "v0" Version string // RoutesContracts is an array of RouteContract used to define the Routes on the contract RoutesContracts []RouteContract }
ServiceContract holds the Contract description of a service
func (*ServiceContract) RouteContractByLabel ¶
func (sc *ServiceContract) RouteContractByLabel(label string) *RouteContract
RouteContractByLabel returns the route contract for the given label
func (*ServiceContract) RouteUrl ¶
func (sc *ServiceContract) RouteUrl(label string) (string, error)
func (*ServiceContract) Suffix ¶
func (sc *ServiceContract) Suffix() string
type ServiceProvider ¶
type ServiceProvider interface { // Start inits the main process executed by the service Start() // Stop terminates all processes related to the service Stop() error // Status returns information about the health of the service Status() *ServiceStatus }
Service providers are constructs able to start, stop and show it's current health (heartbeat)