Documentation ¶
Index ¶
- Constants
- func NormalizeInternalEPs(ieps ...*httpserver.Endpoint) []httpserver.Endpoint
- func NormalizeInternalServiceRoot(absPath string) string
- func PingHandler(c *gin.Context)
- func UptimeHandler(c *gin.Context)
- type Application
- func (a *Application) ActivatePlugins() error
- func (a *Application) AddInitializationHooks(hooks ...func(a *Application) error)
- func (a *Application) AddShutdownHooks(hooks ...func(a *Application) error)
- func (a *Application) Graceful(srv *http.Server, timeout time.Duration)
- func (a *Application) Run(baseCtx context.Context, h http.Handler) error
- func (a *Application) Use(ps ...Plugin) *Application
- type HookError
- type HookErrorType
- type HostInfo
- type InstanceInfo
- type InternalEndpoints
- type Plugin
- type RunArgs
- type State
Constants ¶
const ( DefaultServiceRoot = "/" DefaultInternalServicePath = "/internal" )
Variables ¶
This section is empty.
Functions ¶
func NormalizeInternalEPs ¶
func NormalizeInternalEPs(ieps ...*httpserver.Endpoint) []httpserver.Endpoint
func UptimeHandler ¶
UptimeHandler respond back server start timestamp
Types ¶
type Application ¶
type Application struct { InstanceInfo *InstanceInfo HostInfo *HostInfo // InitializationHooks are hooks that are executed during application initialization. InitializationHooks []func(a *Application) error // ShutdownHooks are hooks that are executed as the application shuts down. ShutdownHooks []func(a *Application) error // The context for the application contains all configuration information // that is needed by the application. Context context.Context // Plugins are used for initializing the application and its respective middleware. Plugins []Plugin BasePath string Valve *valve.Valve State State StartTime time.Time }
func NewApplication ¶
func NewApplication() (*Application, error)
NewApplication TODO: tags are not in use.
func (*Application) ActivatePlugins ¶
func (a *Application) ActivatePlugins() error
ActivatePlugins activates all the registered router for the application. TODO: enhance router to specify dependencies.
func (*Application) AddInitializationHooks ¶
func (a *Application) AddInitializationHooks(hooks ...func(a *Application) error)
AddInitializationHooks adds hooks to run during application initialization. The hooks are run immediately after the application starts and begins listening for HTTP requests.
func (*Application) AddShutdownHooks ¶
func (a *Application) AddShutdownHooks(hooks ...func(a *Application) error)
AddShutdownHooks adds hooks to run immediately before the application is shut down.
func (*Application) Graceful ¶
func (a *Application) Graceful(srv *http.Server, timeout time.Duration)
Graceful shuts down the application by invoking shutdown hooks. Previous behavior was a call to this function would block until an interrupt or terminate signal is relayed by the OS. Now that is handled in Run() so this just needs to clean up.
func (*Application) Run ¶
Run is a method on an instance of an Application that performs TCP listening and serves HTTP/HTTPS. If the Application fails to start, for example due to a TCP port conflict, or an invalid inbound TLS configuration, then this method will return an error. If a severe error condition arises while serving HTTP/HTTPS, this method will panic.
func (*Application) Use ¶
func (a *Application) Use(ps ...Plugin) *Application
Use registers Plugins in the application.
type HookError ¶
type HookError interface { // HookErrorType returns the HookErrorType associated with this particular HookError. HookErrorType() HookErrorType }
HookError defines whether an initialization hook failure is fatal, and the service startup should fail.
type HookErrorType ¶
type HookErrorType int
HookErrorType represents the type of hook error (fatal, non-fatal, etc.)
const ( // NonFatalHookError represents a non-fatal error. Application startup should continue. NonFatalHookError HookErrorType = iota // FatalHookError represents a fatal hook error that will stop application startup. FatalHookError )
type HostInfo ¶
type HostInfo struct {
// contains filtered or unexported fields
}
type InstanceInfo ¶
type InstanceInfo struct {
// contains filtered or unexported fields
}
func NewInstanceInfo ¶
func NewInstanceInfo(name string, tags ...string) *InstanceInfo
func (*InstanceInfo) ID ¶
func (in *InstanceInfo) ID() string
func (*InstanceInfo) Name ¶
func (in *InstanceInfo) Name() string
func (*InstanceInfo) Tags ¶
func (in *InstanceInfo) Tags() []string
func (*InstanceInfo) WithTags ¶
func (in *InstanceInfo) WithTags(tags ...string) *InstanceInfo
type InternalEndpoints ¶
type InternalEndpoints []*httpserver.Endpoint
var StandardInternalEndpoints InternalEndpoints
type Plugin ¶
type Plugin interface { // Activate returns the context after activating the router in the current application. Activate(a *Application) context.Context }
Plugin defines a task that is run to initialize the application context at startup. These tasks are one-time initializations such as creating a gin router
type RunArgs ¶
type RunArgs struct { // Name is the Name of the current application. Name string // Secure determines whether the application's HTTP Port // should have TLS enabled or not. Secure bool // Port is the Port the current application should run on Port int }
RunArgs contains the parsed arguments for configuring the application.
func RunArguments ¶
RunArguments creates an RunArgs struct from parsing os.Args and the application arguments. Note this should only be called once during an application's lifecycle (typically at startup).