Documentation
¶
Index ¶
- Constants
- Variables
- func CORSMiddleware() gin.HandlerFunc
- func GetRouter(mgr process.Manager) (*gin.Engine, error)
- func SetDebugMode(debug bool)
- func Spawn(ctx context.Context, config *Config) (*process.Process, error)
- type Config
- type Dispatcher
- type DispatcherProc
- type Document
- type ErrorDocument
- type Server
Constants ¶
const ( // "GetRouter" command. CmdGetRouter string = "dispatcher.getrouter" )
const (
MinimumTimeout = 5
)
Variables ¶
var ( // List of allowed HTTP headers. AllowedHeaders = []string{ "Content-Type", "Content-Length", "Accept-Encoding", "X-CSRF-Token", "Authorization", "Accept", "Origin", "Cache-Control", "X-Requested-With", } // List of allowed HTTP methods. AllowedMethods = []string{ "POST", "OPTIONS", "GET", "PUT", "DELETE", "PATCH", } )
var ( // Triggered when no process manager instance is provided. ErrNoProcessManager = errors.Base("no process manager") // Triggered when no API dispatcher instance is provided. ErrNoDispatcherProc = errors.Base("no dispatcher process") // Triggered if the process responds with an unexpected data type. ErrWrongReturnType = errors.Base("wrong return type") )
Functions ¶
func GetRouter ¶
Get the router currently in use by the registered dispatcher process.
Should no dispatcher process be in the process manager, then `ErrNoDispatcherProc` will be returned.
Should the dispatcher process return an unexpected value type, then `ErrWrongReturnType` will be returned.
func SetDebugMode ¶
func SetDebugMode(debug bool)
Set debug mode to the given flag.
This will reconfigure Gin-Gonic to either 'release' or 'debug' mode depending on the boolean value of the flag.
Types ¶
type Config ¶
type Config struct {
// Network address that the server will bind to.
//
// This is in the format of <address>:<port>.
// To bind to all available addresses, specify ":<port>" only.
Addr string `json:"address"`
// Path to an SSL certificate file if TLS is required.
Cert string `json:"cert_file"`
// Path to an SSL key file if TLS is required.
Key string `json:"key_file"`
// Should the server use TLS?
UseTLS bool `json:"use_tls"`
// Path to the log file for the server.
LogFile string `json:"log_file"`
// contains filtered or unexported fields
}
API server configuration.
func NewDefaultConfig ¶
func NewDefaultConfig() *Config
Create a new default configuration.
This will create a configuration that has default values.
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
API route dispatcher.
func NewDefaultDispatcher ¶
func NewDefaultDispatcher() *Dispatcher
Create a new API route dispatcher with default values.
The dispatcher returned by this function will listen on port 8080 and bind to all available addresses on the host machine.
func NewDispatcher ¶
func NewDispatcher(lgr logger.Logger, config *Config) *Dispatcher
Create a new API route dispatcher.
func (*Dispatcher) GetRouter ¶
func (d *Dispatcher) GetRouter() *gin.Engine
Return the router used by this dispatcher.
type DispatcherProc ¶
type DispatcherProc struct {
// contains filtered or unexported fields
}
Dispatcher process.
func NewDispatcherProc ¶
func NewDispatcherProc(lgr logger.Logger, config *Config) *DispatcherProc
Create a new dispatcher process.
func (*DispatcherProc) Invoke ¶ added in v1.0.5
func (p *DispatcherProc) Invoke(event events.Event) events.Event
Send an event to the process's responder chain.
Implements `responder.Respondable`.
func (*DispatcherProc) Name ¶ added in v1.0.5
func (p *DispatcherProc) Name() string
Return the name of the process's responder component.
Implements `responder.Respondable`.
func (*DispatcherProc) RespondsTo ¶ added in v1.0.5
func (p *DispatcherProc) RespondsTo(event events.Event) bool
Return if the process responds to the given event.
Implements `responder.Respondable`.
func (*DispatcherProc) Type ¶ added in v1.0.5
func (p *DispatcherProc) Type() string
Return the type of the process's responder component.
Implements `responder.Respondable`.
type Document ¶
type Document struct {
// JSON document data.
Data any `json:"data,omitempty"`
// Number of elements present should `Data` be an array of some kind.
Count int64 `json:"count"`
// Error document.
Error *ErrorDocument `json:"error,omitempty"`
// Time taken to generate the JSON document.
Elapsed string `json:"elapsed_time,omitempty"`
// contains filtered or unexported fields
}
JSON document.
func NewErrorDocument ¶
Create a new JSON document with an embedded error document.
func (*Document) SetError ¶
func (d *Document) SetError(err *ErrorDocument)
Set the `Error` component of the document.
type ErrorDocument ¶
type ErrorDocument struct {
// HTTP status code.
Status int `json:"status"`
// Message describing the error.
Message string `json:"message"`
}
JSON error document.
func NewError ¶
func NewError(status int, msg string) *ErrorDocument
Create a new error document with the given status and message.
type Server ¶
type Server interface {
// Bind and listen to configured address/port and serve HTTPS requests.
ListenAndServeTLS(string, string) error
// Bind and listen to configured address/port and serve HTTP requests.
ListenAndServe() error
// Shut down the API server.
Shutdown(context.Context) error
// Set the TLS configuration for HTTPS mode.
SetTLSConfig(*tls.Config)
}
API server.
func NewDefaultServer ¶
func NewDefaultServer() Server
Create a new API server using default configuration. This will create a new server configured for HTTP only.