Documentation
¶
Index ¶
- Variables
- func Split(source []byte, dest [][]byte) [][]byte
- type ColorServiceReporter
- func (*ColorServiceReporter) AfterApplyConfiguration(service Service, conf interface{}, err error)
- func (*ColorServiceReporter) AfterLoadConfiguration(service Service, conf interface{}, err error)
- func (*ColorServiceReporter) AfterStart(service Service, err error)
- func (*ColorServiceReporter) BeforeApplyConfiguration(service Service)
- func (*ColorServiceReporter) BeforeBegin(service Service)
- func (*ColorServiceReporter) BeforeLoadConfiguration(service Service)
- func (*ColorServiceReporter) BeforeStart(service Service)
- type ConfigurationLoader
- type ConfigurationUnmarshaler
- type ConfigurationUnmarshalerYaml
- type ConfigurationUnmarshelerJson
- type Context
- type FasthttpService
- type FasthttpServiceConfiguration
- type FileConfigurationLoader
- type Handler
- type Middleware
- type NopServiceReporter
- func (*NopServiceReporter) AfterApplyConfiguration(service Service, conf interface{}, err error)
- func (*NopServiceReporter) AfterLoadConfiguration(service Service, conf interface{}, err error)
- func (*NopServiceReporter) AfterStart(service Service, err error)
- func (*NopServiceReporter) BeforeApplyConfiguration(service Service)
- func (*NopServiceReporter) BeforeBegin(service Service)
- func (*NopServiceReporter) BeforeLoadConfiguration(service Service)
- func (*NopServiceReporter) BeforeStart(service Service)
- type Routable
- type Router
- func (router *Router) DELETE(path string, handler Handler, middlewares ...Middleware)
- func (router *Router) GET(path string, handler Handler, middlewares ...Middleware)
- func (router *Router) Group(path string, middlewares ...Middleware) Routable
- func (router *Router) HEAD(path string, handler Handler, middlewares ...Middleware)
- func (router *Router) Handler(fCtx *fasthttp.RequestCtx)
- func (router *Router) OPTIONS(path string, handler Handler, middlewares ...Middleware)
- func (router *Router) PATCH(path string, handler Handler, middlewares ...Middleware)
- func (router *Router) POST(path string, handler Handler, middlewares ...Middleware)
- func (router *Router) PUT(path string, handler Handler, middlewares ...Middleware)
- type Service
- type ServiceStarter
- type ServiceStarterReporter
Constants ¶
This section is empty.
Variables ¶
var ( StrApplicationJson = []byte("application/json") StrXForwardedFor = []byte("X-Forwarded-For") )
var ( ErrWrongConfigurationInformed = errors.New("wrong configuration informed") ErrServiceNotRunning = errors.New("service not running") )
Functions ¶
Types ¶
type ColorServiceReporter ¶
type ColorServiceReporter struct{}
func (*ColorServiceReporter) AfterApplyConfiguration ¶
func (*ColorServiceReporter) AfterApplyConfiguration(service Service, conf interface{}, err error)
func (*ColorServiceReporter) AfterLoadConfiguration ¶
func (*ColorServiceReporter) AfterLoadConfiguration(service Service, conf interface{}, err error)
func (*ColorServiceReporter) AfterStart ¶
func (*ColorServiceReporter) AfterStart(service Service, err error)
func (*ColorServiceReporter) BeforeApplyConfiguration ¶
func (*ColorServiceReporter) BeforeApplyConfiguration(service Service)
func (*ColorServiceReporter) BeforeBegin ¶
func (*ColorServiceReporter) BeforeBegin(service Service)
func (*ColorServiceReporter) BeforeLoadConfiguration ¶
func (*ColorServiceReporter) BeforeLoadConfiguration(service Service)
func (*ColorServiceReporter) BeforeStart ¶
func (*ColorServiceReporter) BeforeStart(service Service)
type ConfigurationLoader ¶
type ConfigurationLoader interface {
// Load receives the `id` of the configuration and Unmarshals it
// int the `dst` pointer. If no error is reported the method will
// return nil otherwise the error will be returned.
Load(id string) ([]byte, error)
}
ConfigurationLoader defines the contract to load a configuration from a repository.
The repository is an abstract idea that can be represented as a directory, a S3 bucket, or "anything" else.
type ConfigurationUnmarshaler ¶
ConfigurationUnmarshaler describes the unmarshaling contract of a configuration.
type ConfigurationUnmarshalerYaml ¶
type ConfigurationUnmarshalerYaml struct {
}
var DefaultConfigurationUnmarshalerYaml ConfigurationUnmarshalerYaml
func (*ConfigurationUnmarshalerYaml) Unmarshal ¶
func (loader *ConfigurationUnmarshalerYaml) Unmarshal(buff []byte, dst interface{}) error
Unmarshal is an abstract method that should be override
type ConfigurationUnmarshelerJson ¶
type ConfigurationUnmarshelerJson struct {
}
var DefaultConfigurationUnmarshalerJson ConfigurationUnmarshelerJson
func (*ConfigurationUnmarshelerJson) Unmarshal ¶
func (loader *ConfigurationUnmarshelerJson) Unmarshal(buff []byte, dst interface{}) error
Unmarshal is an abstract method that should be override
type Context ¶
type Context struct {
Ctx *fasthttp.RequestCtx
Response *fasthttp.Response
Request *fasthttp.Request
}
Context is the wrapper structure on top of the fasthttp.
func NewContext ¶
func NewContext(ctx *fasthttp.RequestCtx) *Context
NewContext returns a new `Context` from a `fasthttp.RequestCtx`.
func (*Context) BodyJson ¶
BodyJson tries to Unmarshal the body content of the request as a JSON file. The destiny of the unmarshaled data is placed into the passed `dst` pointer. If the unmarshaling process fails `BodyJson` will return an error.
func (*Context) SendJson ¶
SendJson marshals the given `obj` and then uses the `SendJsonBytes` to deliver the information to the response.
func (*Context) SendJsonBytes ¶
SendJsonBytes prepares the repsonse header to send the JSON Data. Afterwards, it appends the received `data` to the body.
type FasthttpService ¶
type FasthttpService struct {
Router *Router
Configuration FasthttpServiceConfiguration
Listener net.Listener
Server fasthttp.Server
// contains filtered or unexported fields
}
FasthttpService implements the server for starting
func (*FasthttpService) ApplyConfiguration ¶
func (service *FasthttpService) ApplyConfiguration(configuration interface{}) error
ApplyConfiguration checks if the passing interface is a `FasthttpServiceConfiguration` and applies its configuration to the service.
func (*FasthttpService) LoadConfiguration ¶
func (service *FasthttpService) LoadConfiguration() (interface{}, error)
LoadConfiguration does not do anything in this implementation. This methods is just a placeholder to be overwritten on its usage.
func (*FasthttpService) Restart ¶
func (service *FasthttpService) Restart() error
Reload returns an error due to fasthttp not being able to stop the service.
func (*FasthttpService) Start ¶
func (service *FasthttpService) Start() error
Start ListenAndServe the server. This method is blocking because it uses the fasthttp.ListenAndServe implementation.
func (*FasthttpService) Stop ¶
func (service *FasthttpService) Stop() error
Stop closes the listener and waits the `Start` to stop.
type FasthttpServiceConfiguration ¶
type FasthttpServiceConfiguration struct {
Bind string
}
FasthttpServiceConfiguration keeps all the configuration needed to start the `FasthttpService`.
type FileConfigurationLoader ¶
type FileConfigurationLoader struct {
Directory string
}
func NewFileConfigurationLoader ¶
func NewFileConfigurationLoader(dir string) *FileConfigurationLoader
type Middleware ¶
Middleware is the descriptor of a middleware that wraps a handler.
A middleware implementation will receive a `*Context` and a `next` as a representation of the next middleware (or the end handler itself) that should be called if the endpoint execution should carry on.
If you need to avoid the endpoint execution to continue, you should not to call the `next` handler.
type NopServiceReporter ¶
type NopServiceReporter struct{}
func (*NopServiceReporter) AfterApplyConfiguration ¶
func (*NopServiceReporter) AfterApplyConfiguration(service Service, conf interface{}, err error)
func (*NopServiceReporter) AfterLoadConfiguration ¶
func (*NopServiceReporter) AfterLoadConfiguration(service Service, conf interface{}, err error)
func (*NopServiceReporter) AfterStart ¶
func (*NopServiceReporter) AfterStart(service Service, err error)
func (*NopServiceReporter) BeforeApplyConfiguration ¶
func (*NopServiceReporter) BeforeApplyConfiguration(service Service)
func (*NopServiceReporter) BeforeBegin ¶
func (*NopServiceReporter) BeforeBegin(service Service)
func (*NopServiceReporter) BeforeLoadConfiguration ¶
func (*NopServiceReporter) BeforeLoadConfiguration(service Service)
func (*NopServiceReporter) BeforeStart ¶
func (*NopServiceReporter) BeforeStart(service Service)
type Routable ¶
type Routable interface {
DELETE(path string, handler Handler, middlewares ...Middleware)
GET(path string, handler Handler, middlewares ...Middleware)
HEAD(path string, handler Handler, middlewares ...Middleware)
OPTIONS(path string, handler Handler, middlewares ...Middleware)
PATCH(path string, handler Handler, middlewares ...Middleware)
POST(path string, handler Handler, middlewares ...Middleware)
PUT(path string, handler Handler, middlewares ...Middleware)
Group(path string, middlewares ...Middleware) Routable
}
type Router ¶
type Router struct {
NotFound Handler
// contains filtered or unexported fields
}
func (*Router) DELETE ¶
func (router *Router) DELETE(path string, handler Handler, middlewares ...Middleware)
func (*Router) GET ¶
func (router *Router) GET(path string, handler Handler, middlewares ...Middleware)
func (*Router) HEAD ¶
func (router *Router) HEAD(path string, handler Handler, middlewares ...Middleware)
func (*Router) Handler ¶
func (router *Router) Handler(fCtx *fasthttp.RequestCtx)
func (*Router) OPTIONS ¶
func (router *Router) OPTIONS(path string, handler Handler, middlewares ...Middleware)
func (*Router) PATCH ¶
func (router *Router) PATCH(path string, handler Handler, middlewares ...Middleware)
type Service ¶
type Service interface {
// Name identifies the service.
Name() string
// Loads the configuration. If successful nil will be returned, otherwise
// the error.
LoadConfiguration() (interface{}, error)
// Applies a given configuration object to the service. If successful nil
// will be returned, otherwise the error.
ApplyConfiguration(interface{}) error
// Restarts the service. If successful nil will be returned, otherwise the
// error.
Restart() error
// Start starts the service. If successful nil will be returned, otherwise
// the error.
Start() error
// Stop stops the service. If successful nil will be returned, otherwise the
// error.
Stop() error
}
Service is an abstraction for implementing parts that can be loaded, reloaded, started and stopped inside of the system.
Maybe you can implement your HTTP service like this, or your Redis resource. As simple and wide as it could be this directive will provide an defined signature to implement all your resources.
type ServiceStarter ¶
type ServiceStarter struct {
// contains filtered or unexported fields
}
func NewServiceStarter ¶
func NewServiceStarter(services []Service, reporter ServiceStarterReporter) *ServiceStarter
func (*ServiceStarter) Start ¶
func (engineStarter *ServiceStarter) Start() error
type ServiceStarterReporter ¶
type ServiceStarterReporter interface {
BeforeBegin(service Service)
BeforeLoadConfiguration(service Service)
AfterLoadConfiguration(service Service, conf interface{}, err error)
BeforeApplyConfiguration(service Service)
AfterApplyConfiguration(service Service, conf interface{}, err error)
BeforeStart(service Service)
AfterStart(service Service, err error)
}