ha

package
v1.2.14 Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEndpointNotFound   = errors.New("endpoint not found")
	ErrChainNotFound      = errors.New("chain not found")
	ErrTypeNotMatched     = errors.New("type not matched")
	ErrEmptyChain         = errors.New("empty chain")
	ErrMiddlewareNotFound = errors.New("middleware not found")

	// PriorityDefault is the default priority for chains, which is the lowest priority
	PriorityDefault = -1
	// PriorityLow is the second-lowest priority
	PriorityLow = 0
	// PriorityNormal is the normal priority
	PriorityNormal = 1 << 16
	// PriorityHigh is the second-highest priority
	PriorityHigh = 1 << 32
	// PriorityEmergency is the highest priority
	PriorityEmergency = 1 << 48
)

Functions

func GetMiddleware

func GetMiddleware(name string) (middleware gin.HandlersChain, err error)

func ParseConfig

func ParseConfig(config EngineConfig) (engine *http.Engine, err error)

func ParseRouter

func ParseRouter(config RouterConfig) (group *http.EndpointGroup, err error)

func RegisterArrangedChain

func RegisterArrangedChain[request, response any](name string, fns ...http.Handler[request, response])

func RegisterEndPoint

func RegisterEndPoint[request, response any](name string, allocRequest request, allocResponse response)

func RegisterMiddleware

func RegisterMiddleware(name string, middleware gin.HandlersChain)

func RegisterPriorityArrangedChain

func RegisterPriorityArrangedChain[request, response any](name string, priority int, fns ...http.Handler[request, response])

Types

type Arranged

type Arranged interface {
	UniqueName() string
	Priority() int
	RequestType() reflect.Type
	ResponseType() reflect.Type
}

type ArrangedChain

type ArrangedChain[request, response any] interface {
	Arranged
	Chain() http.Chain[request, response]
	Request() request
	Response() response
}

func GetArrangedChain

func GetArrangedChain[request, response any](name string, req request, res response) (chain ArrangedChain[request, response], err error)

func NewArrangedChain

func NewArrangedChain[request, response any](name string, chain http.Chain[request, response]) ArrangedChain[request, response]

func NewArrangedChainWithPriority

func NewArrangedChainWithPriority[request, response any](name string, priority int, chain http.Chain[request, response]) ArrangedChain[request, response]

type ArrangedEndPoint

type ArrangedEndPoint interface {
	UniqueName() string
	ParseConfig(opts EndPointConfig) (endpoint http.EndPointInterface, err error)
}

func GetEndPoint

func GetEndPoint(name string) (endpoint ArrangedEndPoint, err error)

type EndPointConfig

type EndPointConfig struct {
	Name        string       `json:"name" yaml:"name"`
	Path        string       `json:"path" yaml:"path"`
	Methods     []string     `json:"methods" yaml:"methods"`
	Chains      []string     `json:"chains" yaml:"chains"`
	Middlewares []string     `json:"middlewares,omitempty" yaml:"middlewares,omitempty"`
	Headers     ParamsConfig `json:"headers,omitempty" yaml:"headers,omitempty"`
	Paths       ParamsConfig `json:"paths,omitempty" yaml:"paths,omitempty"`
	Queries     ParamsConfig `json:"queries,omitempty" yaml:"queries,omitempty"`
	Cookies     ParamsConfig `json:"cookies,omitempty" yaml:"cookies,omitempty"`
}

type EngineConfig

type EngineConfig struct {
	Bind    string       `json:"bind" yaml:"bind" xml:"bind"`
	Router  RouterConfig `json:"router" yaml:"router" xml:"router"`
	Serving bool         `json:"serving" yaml:"serving" xml:"serving"`
	Path    string       `json:"path,omitempty" yaml:"path,omitempty" xml:"path,omitempty"`
	Block   bool         `json:"block,omitempty" yaml:"block,omitempty" xml:"block,omitempty"`
}

type ParamsConfig

type ParamsConfig struct {
	Necessary  []string `json:"necessary,omitempty" yaml:"necessary,omitempty" xml:"necessary,omitempty"`
	Additional []string `json:"additional,omitempty" yaml:"additional,omitempty" xml:"additional,omitempty"`
}

type RouterConfig

type RouterConfig struct {
	Path       string           `json:"path" yaml:"path" xml:"path"`
	SubRouters []RouterConfig   `json:"sub_routers,omitempty" yaml:"sub_routers,omitempty" xml:"sub_routers,omitempty"`
	EndPoints  []EndPointConfig `json:"endpoints,omitempty" yaml:"endpoints,omitempty" xml:"endpoints,omitempty"`
}

Jump to

Keyboard shortcuts

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