http

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2019 License: GPL-3.0 Imports: 19 Imported by: 2

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 ErrorMapper

type ErrorMapper 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 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 MType

type MType string

type Middleware

type Middleware func(ctx *Ctx) (*Ctx, error)

type Option

type Option func(ss *HttpService)

func WithErrorMapping

func WithErrorMapping(em ErrorMapper) Option

func WithFastHttpEnhancer

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

func WithMiddlewares

func WithMiddlewares(mws ...Middleware) Option

func WithPostProcessors

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

func WithUnimplErrorMapper

func WithUnimplErrorMapper(em UnimplMethodErrorMapper) 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() RestClient

type UnimplMethodErrorMapper

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

Jump to

Keyboard shortcuts

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