echo

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2021 License: MIT Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const DefaultProviderName = "echo"

Variables

This section is empty.

Functions

func CORSDefault

func CORSDefault() echo.MiddlewareFunc

CORSDefault allows requests from any origin wth GET, HEAD, PUT, POST or DELETE method.

func Get

func Get(ctx context.Context) (httpsrv.Provider, error)

func GetEnity

func GetEnity(ctx context.Context, enityName string) (interface{}, error)

func Handler

func Handler(f HandlerFunc) echo.HandlerFunc

func HandlerLogger

func HandlerLogger(parent *zerolog.Logger, ec echo.Context) (log zerolog.Logger, requestID string, err error)

HandlerLogger handler that adds requesID into logger fields

func HydrationLogger added in v0.2.0

func HydrationLogger(log *zerolog.Logger) echo.MiddlewareFunc

func HydrationRequestID

func HydrationRequestID() echo.MiddlewareFunc

func Registrate

func Registrate(ctx context.Context) (context.Context, error)

func RegistrateEnity

func RegistrateEnity(ctx context.Context, enityName string, options interface{}) (context.Context, error)

Types

type Config

type Config struct {
	// Address is an address on which HTTP server will listen.
	Address string `envconfig:"optional"`
	// DisableHTTP2 disabled HTTP2 features (only HTTP 1.0/1.1 will work).
	DisableHTTP2 bool `envconfig:"optional"`
	// Debug enables internal echo debugging features.
	Debug bool `envconfig:"optional"`
	// HideBanner disables showing Echo banner on server's start.
	HideBanner bool `envconfig:"optional"`
	// HidePort disables showing address and port on which Echo will listen
	// for connections.
	HidePort bool `envconfig:"optional"`
	// Path to certificate for HTTPS
	CertFile string `envconfig:"optional"`
	// Path to key for HTTPS
	KeyFile string `envconfig:"optional"`

	// Timeouts
	// BodyReadTimeout sets body reading timeout in seconds. Defaults
	// to 10 seconds.
	BodyReadTimeout time.Duration `envconfig:"optional"`
	// BodyWriteTimeout sets body writing timeout in seconds. Defaults
	// to 10 seconds.
	BodyWriteTimeout time.Duration `envconfig:"optional"`
	// HeaderReadTimeout sets headers reading timeout in seconds. Defaults
	// to 5 seconds.
	HeaderReadTimeout time.Duration `envconfig:"optional"`

	// Middlewares for server endpoints
	Middlewares []interface{} `envconfig:"-"`
}

func (*Config) Copy

func (sc *Config) Copy() *Config

func (*Config) InitilizeEcho

func (sc *Config) InitilizeEcho(e *echo.Echo)

func (*Config) Validate

func (sc *Config) Validate() error

Checks for necessity for default values.

type Context

type Context struct {
	echo.Context
}

func (Context) AddToSwagger added in v0.4.0

func (ec Context) AddToSwagger() swagger.IMethod

func (Context) BadRequest added in v0.4.0

func (ec Context) BadRequest(err error) error

BadRequest return err 400

func (Context) CreateFailed added in v0.4.0

func (ec Context) CreateFailed(err error) error

CreateFailed return err 409

func (Context) Forbidden added in v0.4.0

func (ec Context) Forbidden(err error) error

Forbidden return err 403

func (Context) GetInt64Param added in v0.4.0

func (ec Context) GetInt64Param(param string) (int64, error)

func (Context) GetLog added in v0.4.0

func (ec Context) GetLog() *zerolog.Logger

func (Context) GetReqID added in v0.4.0

func (ec Context) GetReqID() string

func (Context) HasExpired added in v0.4.0

func (ec Context) HasExpired(err error) error

HasExpired return err 408

func (Context) InternalServerError added in v0.4.0

func (ec Context) InternalServerError(err error) error

InternalServerError return err 500

func (Context) IsBuildingSwagger added in v0.4.0

func (ec Context) IsBuildingSwagger() bool

func (Context) NotDeleted added in v0.4.0

func (ec Context) NotDeleted(err error) error

NotDeleted return err 406

func (Context) NotFound added in v0.4.0

func (ec Context) NotFound(err error) error

NotFound return err 404

func (Context) NotUpdated added in v0.4.0

func (ec Context) NotUpdated(err error) error

NotUpdated return err 409

func (Context) OK added in v0.4.0

func (ec Context) OK(data interface{}) error

func (Context) OkResult added in v0.4.0

func (ec Context) OkResult() error

func (Context) Unauthorized added in v0.4.0

func (ec Context) Unauthorized(err error) error

Unauthorized return err 401

type Enity

type Enity struct {

	// Server is an echo.Echo thing that represents HTTP server.
	Server *echo.Echo
	// contains filtered or unexported fields
}

Enity describes every HTTP server's structure and configuration.

func GetEnityTypeCast

func GetEnityTypeCast(ctx context.Context, enityName string) (*Enity, error)

func NewEnity

func NewEnity(ctx context.Context, serverName string, options interface{}) (*Enity, error)

Create configures structure and creates new echo HTTP server.

func (*Enity) BuildSwagger

func (srv *Enity) BuildSwagger()

BuildSwagger build/rebuild swagger for all apiGroups

func (*Enity) CreateAPIVersionGroup

func (srv *Enity) CreateAPIVersionGroup(apiVersion string, middlewares ...interface{}) error

CreateAPIVersionGroup creates routing group for desired API version. If API group was already created it will return nil and error about that.

func (*Enity) GetAPIVersionGroup

func (srv *Enity) GetAPIVersionGroup(apiVersion string) (*Group, error)

GetAPIVersionGroup will return created API version routing group. It will return nil and error if API group wasn't created.

func (*Enity) IsStarted

func (srv *Enity) IsStarted() bool

IsStarted return server state

func (*Enity) RegisterEndpoint

func (srv *Enity) RegisterEndpoint(method, endpoint string, handler http.Handler, m ...httpsrv.MiddleWareFunc) error

func (*Enity) Shutdown

func (srv *Enity) Shutdown() error

Shutdown stops HTTP server listening.

func (*Enity) Start

func (srv *Enity) Start() error

Start starts HTTP server listening.

type Group

type Group struct {
	echo.Group
}

func GetAPIVersionGroup added in v0.2.0

func GetAPIVersionGroup(ctx context.Context, enityName, apiVersion string) (*Group, error)

func (*Group) ToEchoGroup

func (gr *Group) ToEchoGroup() *echo.Group

type HandlerFunc

type HandlerFunc func(Context) error

type Provider

type Provider struct {
	*provider.Provider
}

Provider is a HTTP server provider using labstack's Echo HTTP framework.

func NewProvider

func NewProvider(ctx context.Context) *Provider

Initialize should initialize provider. If asynchronous mode supported by provider (e.g. for batch inserting using transactions) queue processor should also be started here.

func (*Provider) CreateAPIVersionGroup

func (p *Provider) CreateAPIVersionGroup(serverName, apiVersion string, middlewares ...interface{},
) error

CreateAPIVersionGroup creates requested API version routes group. Passed apiVersion should be a string with API version without leading "v", "version" or anything like that.

func (*Provider) CreateEnity

func (p *Provider) CreateEnity(enityName string, options interface{}) error

CreateEnity should create enity using passed parameters.

func (*Provider) GetAPIVersionGroup

func (p *Provider) GetAPIVersionGroup(serverName, apiVersion string) (interface{}, error)

GetAPIVersionGroup returns routes grouping for passed apiVersion. Passed apiVersion should be a string with API version without leading "v", "version" or anything like that.

func (*Provider) GetEnity

func (p *Provider) GetEnity(connectionName string) (interface{}, error)

GetEnity should return pointer to connection structure to caller.

func (*Provider) RegisterEndpoint

func (p *Provider) RegisterEndpoint(
	serverName, method, endpoint string,
	handler http.Handler,
	middleware ...httpsrv.MiddleWareFunc) error

RegisterEndpoint register endpoint on HTTP server.

Jump to

Keyboard shortcuts

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