app

package
v0.0.0-...-baea68c Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultServiceRoot         = "/"
	DefaultInternalServicePath = "/internal"
)

Variables

This section is empty.

Functions

func NormalizeInternalEPs

func NormalizeInternalEPs(ieps ...*httpserver.Endpoint) []httpserver.Endpoint

func NormalizeInternalServiceRoot

func NormalizeInternalServiceRoot(absPath string) string

func PingHandler

func PingHandler(c *gin.Context)

PingHandler respond back 200 OK

func UptimeHandler

func UptimeHandler(c *gin.Context)

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

func (a *Application) Run(baseCtx context.Context, h http.Handler) error

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
}

func NewHostInfo

func NewHostInfo(host string, port int, secure bool) *HostInfo

func (*HostInfo) Host

func (info *HostInfo) Host() string

func (*HostInfo) IsSecure

func (info *HostInfo) IsSecure() bool

IsSecure is true if TLS should be enabled on the HTTP Port, false otherwise.

func (*HostInfo) Port

func (info *HostInfo) Port() int

func (*HostInfo) SetPort

func (info *HostInfo) SetPort(port int)

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

func RunArguments() (*RunArgs, error)

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).

type State

type State uint8

State App state

const (
	ReadyToStart State
	Starting
	Stopping
	Up
	Down
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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