app

package
v0.0.0-...-86833b7 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2023 License: MIT Imports: 12 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = New()
View Source
var KernelType = reflect.TypeOf((*Kernel)(nil))

Functions

func Env

func Env(def, key string, fallbacks ...string) string

Env works as Getenv but the first argument is a default value

func Getenv

func Getenv(key string, fallbacks ...string) (value string)

Getenv same as os.Getenv, but with fallback support

func LookupEnv

func LookupEnv(Key string, fallbacks ...string) (value string, found bool)

LookupEnv same as os.LookupEnv, but with fallback support

Types

type Component

type Component interface {
	Bootstrap(app *Kernel)
}

Component represents a service component, a component need to implement a bootstrap method which is responsible to set up the component with the app, ex: register a type Providers, or add middleware handler

func NewComponentBundle

func NewComponentBundle(components ...Component) Component

func NewCtlComponent

func NewCtlComponent(controllers ...Controller) Component

NewCtlComponent creates a component that will bind the passed context at bootstrap

type ComponentFunc

type ComponentFunc func(*Kernel)

ComponentFunc func implementing Component interface

func (ComponentFunc) Bootstrap

func (component ComponentFunc) Bootstrap(a *Kernel)

type Controller

type Controller interface {
	Mx(*Mapper)
}

type ControllerURLGen

type ControllerURLGen struct {
	Parent common.URLGen
	// contains filtered or unexported fields
}

func (*ControllerURLGen) URL

func (urlGen *ControllerURLGen) URL(dst string, v ...interface{}) string

type Kernel

type Kernel struct {
	Registry *container.Registry // Kernel Registry dependency injection context
	Router   *router.Router      // Router
	Prefix   string              // Prefix prefix for path added in this app
	URLGen   MapURLGen
	// contains filtered or unexported fields
}

Kernel app holds your top level data for you service

Router, Dispatcher, Scope

func GetKernel

func GetKernel(c *container.Registry) *Kernel

func New

func New() *Kernel

func (*Kernel) AddControllers

func (kernel *Kernel) AddControllers(contexts ...Controller)

func (*Kernel) AddHandler

func (kernel *Kernel) AddHandler(method, path string, handler request.Handler, filters ...request.Handler)

AddHandler register a handler, see: request.Handler

func (*Kernel) AddHandlerContextName

func (kernel *Kernel) AddHandlerContextName(registry *container.Registry, name, method, path string, handler request.Handler, filters ...request.Handler)

AddHandlerContextName accepts a context, a Name identifier, http method|methods, pattern path, handler and filters ex: one handler app.AddHandlerContextName(myContext,"mySectionIdentifier","GET", "/public",fileServer,checkAuth)

multiples handles app.AddHandlerContextName(myContext,"mySectionIdentifier","GET|POST|SEARCH", "/products",productHandler,checkAuth)

func (*Kernel) AddHandlerFunc

func (kernel *Kernel) AddHandlerFunc(method, path string, fn request.HandlerFunc, filters ...request.Handler)

AddHandlerFunc register a func handler, see: request.Handler

func (*Kernel) AddHandlerName

func (kernel *Kernel) AddHandlerName(name, method, path string, handler request.Handler, filters ...request.Handler)

AddHandlerName register a named handler, see: request.Handler

func (*Kernel) BindFilterFuncHandlers

func (filterHandlers *Kernel) BindFilterFuncHandlers(filters ...request.HandlerFunc)

func (*Kernel) BindFilterHandlers

func (filterHandlers *Kernel) BindFilterHandlers(filters ...request.Handler)

BindFilterHandlers adds filters to the request chain

func (*Kernel) Bootstrap

func (kernel *Kernel) Bootstrap(b ...Component)

Bootstrap bootstraps a list of components, a sub scope will be created, and a copy of the original app is used, in such form that modifying the app.Prefix will not reflect outside this call.

func (*Kernel) Container

func (kernel *Kernel) Container() *container.Registry

func (*Kernel) Dispatch

func (kernel *Kernel) Dispatch(eventName string, payload event.Payload)

func (*Kernel) Dispose

func (kernel *Kernel) Dispose()

Dispose End same as app.Registry.End() invoke this func before exiting the app to cleanup

func (*Kernel) Fork

func (kernel *Kernel) Fork() *Kernel

Fork create child app

func (*Kernel) MustDispose

func (kernel *Kernel) MustDispose()

func (*Kernel) ResetMiddleHandlers

func (filterHandlers *Kernel) ResetMiddleHandlers()

ResetMiddleHandlers will clear the registered middlewares

func (*Kernel) Root

func (kernel *Kernel) Root() *Kernel

Root returns the root app

func (*Kernel) RunServer

func (kernel *Kernel) RunServer(host string) error

RunServer runs the server with the specified host Calling this func will emit a "app.run" event in the app

func (*Kernel) RunServerTLS

func (kernel *Kernel) RunServerTLS(host, certfile, keyfile string) error

RunServerTLS runs the server in tls mode Calling this func will emit a "app.run.tls" event in the app

func (*Kernel) Snapshot

func (kernel *Kernel) Snapshot() *Kernel

Snapshot causes a sub app to be created and inserted in the scope calling app.Root will return the created sub app

func (*Kernel) Subscribe

func (kernel *Kernel) Subscribe(eventName string, handler interface{})

type MapURLGen

type MapURLGen map[string]string

func (MapURLGen) URL

func (urlGen MapURLGen) URL(dst string, v ...interface{}) string

type Mapper

type Mapper struct {
	Prefix string
	Name   string

	Registry *container.Registry

	*ControllerURLGen
	// contains filtered or unexported fields
}

func (*Mapper) BindAction

func (mx *Mapper) BindAction(method, path, action string, filters ...request.Handler)

func (*Mapper) BindFilterFuncHandlers

func (filterHandlers *Mapper) BindFilterFuncHandlers(filters ...request.HandlerFunc)

func (*Mapper) BindFilterHandlers

func (filterHandlers *Mapper) BindFilterHandlers(filters ...request.Handler)

BindFilterHandlers adds filters to the request chain

func (*Mapper) ResetMiddleHandlers

func (filterHandlers *Mapper) ResetMiddleHandlers()

ResetMiddleHandlers will clear the registered middlewares

type RunServerEvent

type RunServerEvent struct {
	event.Event
	Host string
	Port string
}

type RunServerEventTLS

type RunServerEventTLS struct {
	event.Event
	Host     string
	CertFile string
	KeyFile  string
}

Jump to

Keyboard shortcuts

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