http

package
v2.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2020 License: GPL-3.0 Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RestMType = MType("rest")
	SoapMType = MType("soap")
)
View Source
const (
	POST = "POST"
	GET  = "GET"
)

Variables

View Source
var (
	ErrNotFunc     = errors.New("'handler' is not a function")
	ErrInvalidFunc = errors.New(`'handler' invalid. Expecting function with (
		[headers: map[string][string]],
		[requestBody: Any], 
		[ctx: *fasthttp.RequestContext]
	) params`)
)

Functions

func CodeToHttpStatus

func CodeToHttpStatus(code codes.Code) int

func HttpStatusToCode

func HttpStatusToCode(status int) codes.Code

func Serve

func Serve(uriPart, filePath string, renderParams ...string) *content

func ServeV2

func ServeV2(uriPart, filePath, contentType string, renderParams ...string) *content

Types

type Ctx

type Ctx struct {
	*fasthttp.RequestCtx
	// contains filtered or unexported fields
}

func (*Ctx) Action

func (c *Ctx) Action() string

func (*Ctx) Error

func (c *Ctx) Error() error

func (*Ctx) Get

func (c *Ctx) Get(key string) interface{}

func (*Ctx) GetInt32

func (c *Ctx) GetInt32(key string) (int32, bool)

func (*Ctx) MappedRequestBody

func (c *Ctx) MappedRequestBody() interface{}

func (*Ctx) MappedResponseBody

func (c *Ctx) MappedResponseBody() interface{}

func (*Ctx) Put

func (c *Ctx) Put(key string, value interface{})

type ErrorHandler

type ErrorHandler func(ctx *Ctx, err error) interface{}

type ErrorResponse

type ErrorResponse struct {
	StatusCode int
	Status     string
	Body       string
}

func (ErrorResponse) Error

func (r ErrorResponse) Error() string

func (ErrorResponse) ToGrpcError

func (r ErrorResponse) ToGrpcError() error

type HandlersInfoSnapshot

type HandlersInfoSnapshot struct {
	// contains filtered or unexported fields
}

func (HandlersInfoSnapshot) String

func (s HandlersInfoSnapshot) String() string

type HttpService

type HttpService struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(opts ...Option) *HttpService

func (*HttpService) GetHandlersSnapshot

func (ss *HttpService) GetHandlersSnapshot() HandlersInfoSnapshot

func (*HttpService) ListenAndServe

func (ss *HttpService) ListenAndServe(bindingAddress string) error

func (*HttpService) Register

func (ss *HttpService) Register(uri, method string, mType MType, handler interface{}) error

func (*HttpService) RegisterControllers

func (ss *HttpService) RegisterControllers(uri string, handlers ...interface{}) error

func (*HttpService) RegisterStatic

func (ss *HttpService) RegisterStatic(list ...*content) error

func (*HttpService) Serve

func (ss *HttpService) Serve(ln net.Listener) error

func (*HttpService) Shutdown

func (ss *HttpService) Shutdown() error

type Interceptor

type Interceptor func(ctx *Ctx, proceed func() (interface{}, error)) (interface{}, error)

type JsonRestClient

type JsonRestClient struct {
	// contains filtered or unexported fields
}

func (*JsonRestClient) Get

func (jrc *JsonRestClient) Get(uri string, responsePtr interface{}) error

func (*JsonRestClient) Invoke

func (jrc *JsonRestClient) Invoke(method, uri string, headers map[string]string, requestBody, responsePtr interface{}) error

func (*JsonRestClient) InvokeWithDynamicResponse

func (jrc *JsonRestClient) InvokeWithDynamicResponse(method, uri string, headers map[string]string, requestBody interface{}) (interface{}, error)

func (*JsonRestClient) InvokeWithoutHeaders

func (jrc *JsonRestClient) InvokeWithoutHeaders(method, uri string, requestBody, responsePtr interface{}) error

func (*JsonRestClient) Post

func (jrc *JsonRestClient) Post(uri string, requestBody, responsePtr interface{}) error

type JsonRestClientOption

type JsonRestClientOption func(client *JsonRestClient)

func WithDefaultTimeout

func WithDefaultTimeout(timeout time.Duration) JsonRestClientOption

func WithFasttHttpEnchacer

func WithFasttHttpEnchacer(f func(*fasthttp.Client)) JsonRestClientOption

type MType

type MType string

type Middleware

type Middleware func(ctx *Ctx) error

type Option

type Option func(ss *HttpService)

func WithErrorHandler

func WithErrorHandler(em ErrorHandler) Option

func WithFastHttpEnhancer

func WithFastHttpEnhancer(enhancer func(s *fasthttp.Server)) Option

func WithInterceptor

func WithInterceptor(interceptor Interceptor) Option

func WithMiddlewares

func WithMiddlewares(mws ...Middleware) Option

func WithPostProcessors

func WithPostProcessors(pp ...func(c *Ctx)) Option

func WithUnimplErrorHandler

func WithUnimplErrorHandler(em UnimplMethodErrorHandler) Option

func WithValidator

func WithValidator(validator Validator) Option

type RESTFault

type RESTFault struct {
	Code   int
	Status string
}

func (*RESTFault) Error

func (rf *RESTFault) Error() string

type RestClient

type RestClient interface {
	Invoke(method, uri string, headers map[string]string, requestBody, responsePtr interface{}) error
	InvokeWithoutHeaders(method, uri string, requestBody, responsePtr interface{}) error
	Post(uri string, requestBody, responsePtr interface{}) error
	Get(uri string, responsePtr interface{}) error
	InvokeWithDynamicResponse(method, uri string, headers map[string]string, requestBody interface{}) (interface{}, error)
}

func NewJsonRestClient

func NewJsonRestClient(opts ...JsonRestClientOption) RestClient

type UnimplMethodErrorHandler

type UnimplMethodErrorHandler func(ctx *Ctx, actionKey string) interface{}

type ValidationErrors

type ValidationErrors struct {
	*RESTFault
	Details map[string]string
}

type Validator

type Validator func(ctx *Ctx, mappedRequestBody interface{}) error

Jump to

Keyboard shortcuts

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