httpsrv

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: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ProvidersName = "httpsrv"
)

Variables

View Source
var (
	ErrEmptyHTTPServers     = errors.New("empty http(s) servers")
	ErrEmptyServerName      = errors.New("empty server name is not allowed")
	ErrServerNotFound       = errors.New("requested server wasn't created yet")
	ErrServerNameMissing    = errors.New("server's name is empty")
	ErrGroupNotFound        = errors.New("requested API version group wasn't found")
	ErrBindAddressMissing   = errors.New("bind address wasn't specified")
	ErrServerAlreadyStarted = errors.New("server already started")
	ErrEmptyHTTPHandler     = errors.New("empty http handler")
	ErrUnknownHTTPMethod    = errors.New("unknown http method")
	ErrServerNotUp          = errors.New("http server isn't up after 10 seconds")
)

Functions

func ErrInvalidGroupPointer

func ErrInvalidGroupPointer(iface interface{}) error

func GetEnity

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

func Registrate

func Registrate(ctx context.Context) context.Context

func RegistrateEnity

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

func RegistrateProvider

func RegistrateProvider(ctx context.Context, name string, p Provider) (context.Context, error)

Types

type ErrorAnsw

type ErrorAnsw struct {
	Body ErrorAnswBody `json:"error"`
}

func BadRequest

func BadRequest(err error) ErrorAnsw

BadRequest return err 400

func CreateFailed

func CreateFailed(err error) ErrorAnsw

CreateFailed return err 409

func Forbidden

func Forbidden(err error) ErrorAnsw

Forbidden return err 403

func HasExpired

func HasExpired(err error) ErrorAnsw

HasExpired return err 408

func InternalServerError

func InternalServerError(err error) ErrorAnsw

InternalServerError return err 500

func NewErrorAnsw

func NewErrorAnsw(statusCode int, code string, err error) ErrorAnsw

NewErrorAnsw create new ErrorAnsw and fills it withcode, statuscode, details

func NotDeleted

func NotDeleted(err error) ErrorAnsw

NotDeleted return err 406

func NotFound

func NotFound(err error) ErrorAnsw

NotFound return err 404

func NotUpdated

func NotUpdated(err error) ErrorAnsw

NotUpdated return err 409

func Unauthorized

func Unauthorized(err error) ErrorAnsw

Unauthorized reurn err 401

func (ErrorAnsw) Error

func (e ErrorAnsw) Error() string

type ErrorAnswBody

type ErrorAnswBody struct {
	Code       string `json:"code"`
	StatusCode int    `json:"statusCode"`
	Details    string `json:"details"`
}

type HTTPServers

type HTTPServers struct {
	*providers.BaseProviders
}

HTTPServers structure controls all HTTP servers for gowork.

func Get

func Get(ctx context.Context) *HTTPServers

func NewHTTPServers

func NewHTTPServers(ctx context.Context) *HTTPServers

func (*HTTPServers) CreateAPIVersionGroup

func (https *HTTPServers) CreateAPIVersionGroup(providerName, serverName, apiVersion string, middlewares ...interface{}) error

CreateAPIVersionGroup creates new API version group using designated provider.

func (*HTTPServers) CreateEnity

func (https *HTTPServers) CreateEnity(providerName, serverName string, options interface{}) error

CreateEnity creates new HTTP server using designated provider.

func (*HTTPServers) GetAPIVersionGroup

func (https *HTTPServers) GetAPIVersionGroup(providerName, serverName, apiVersion string) (interface{}, error)

GetAPIVersionGroup returns HTTP server routing group using designated provider.

func (*HTTPServers) GetEnity

func (https *HTTPServers) GetEnity(providerName, serverName string) (interface{}, error)

GetEnity returns HTTP server controlling structure from designated provider.

func (*HTTPServers) GetProvider

func (https *HTTPServers) GetProvider(providerName string) (Provider, error)

GetProvider returns provider. Returns error if provider isn't registered.

func (*HTTPServers) RegisterEndpoint

func (https *HTTPServers) RegisterEndpoint(
	providerName, serverName, method, endpoint string,
	handler http.Handler,
	m ...MiddleWareFunc) error

RegisterEndpoint register endpoint on selected HTTP server.

type MiddleWareFunc

type MiddleWareFunc func(http.Handler) http.Handler

type Provider

type Provider interface {
	provider.IProvider
	provider.IEnityManager

	// CreateAPIVersionGroup should be responsible for creating
	// routes grouping for specified API version. Version should be
	// a string without leading "v" or "version" or anything like that.
	// Provider should append "v" automatically.
	// Passed group should be a pointer to needed structure that might be
	// provided by HTTP server provider. Provider should not attempt to
	// replace pointer if nil is passed. Provider should check if passed
	// group is a pointer to valid structure.
	// It is up to provider to cast options and middlewares to needed type.
	CreateAPIVersionGroup(serverName string, apiVersion string, middlewares ...interface{}) error
	// GetAPIVersionGroup should return handler for passed version
	// API. Version should be a string without leading "v" or "version"
	// or anything like that. Provider should append "v" automatically.
	// Passed group should be a pointer to needed structure that might be
	// provided by HTTP server provider. Provider should not attempt to
	// replace pointer if nil is passed. Provider should check if passed
	// group is a pointer to valid structure.
	GetAPIVersionGroup(serverName string, apiVersion string) (interface{}, error)
	// Register endpoint on server
	RegisterEndpoint(serverName, method, endpoint string, handler http.Handler, middleware ...MiddleWareFunc) error
}

Provider is an interface every provider should follow.

func GetProvider

func GetProvider(ctx context.Context, name string) (Provider, error)

type ResultAnsw

type ResultAnsw struct {
	Body interface{} `json:"result"`
}

func OkResult

func OkResult() ResultAnsw

OkResult return OK answer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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