v2

package module
v2.0.0-...-73f4b1e Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MatchCodeToMessage = map[int]HttpStatusMsg{
		500: InternalServerError,
		400: BadRequest,
		403: Unauthorized,
		200: OK,
	}
)

Functions

func CallbackBearerAuth

func CallbackBearerAuth(req *Request, data interface{})

func NewHTTPServer

func NewHTTPServer(svc Service, addr string, multicore bool) *httpServer

Types

type Filter

type Filter func(*Request, Service) Response

func AuthenticateAndSetBearerFilter

func AuthenticateAndSetBearerFilter(
	authenticator func(*Request) interface{},
) Filter

func AuthenticateFilter

func AuthenticateFilter(
	authenticator func(*Request) interface{},
	callback func(*Request, interface{}),
) Filter

type GrpcServer

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

func NewGrpcServer

func NewGrpcServer() *GrpcServer

func (*GrpcServer) RegisterHandler

func (s *GrpcServer) RegisterHandler(path string, handler http.Handler)

func (*GrpcServer) Serve

func (s *GrpcServer) Serve(port int32)

type HttpStatusMsg

type HttpStatusMsg string
const (
	InternalServerError HttpStatusMsg = "internal server error"
	BadRequest          HttpStatusMsg = "bad request"
	Unauthorized        HttpStatusMsg = "unauthorized"
	OK                  HttpStatusMsg = "OK"
)

func (HttpStatusMsg) B

func (h HttpStatusMsg) B() []byte

type Request

type Request struct {
	http.Request
	context.Context
}

func (Request) Respond

func (r Request) Respond(body interface{}) Response

Response constructs a new Response to the request, and if non-nil, encodes the given body into it.

func (*Request) Write

func (r *Request) Write(b []byte) (n int, err error)

type Response

type Response struct {
	*http.Response
	Error   error
	Request *Request
}

func LogFilter

func LogFilter(req *Request, svc Service) Response

func NewResponse

func NewResponse(req Request) Response

NewResponse constructs a Response with status code 200.

func NewResponseWithCode

func NewResponseWithCode(req Request, statusCode int) Response

NewResponseWithCode constructs a Response with the given status code.

func TraceFilter

func TraceFilter(req *Request, svc Service) Response

func (*Response) Encode

func (r *Response) Encode(v interface{})

func (*Response) EncodeAsJSON

func (r *Response) EncodeAsJSON(v interface{})

EncodeAsJSON writes the response as JSON. This is the default encoding type when using Encode.

func (*Response) Write

func (r *Response) Write(b []byte) (n int, err error)

Write writes the passed bytes to the response's body.

type Router

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

func RouterForRequest

func RouterForRequest(r Request) *Router

func (*Router) CONNECT

func (r *Router) CONNECT(pattern string, svc Service)

func (*Router) DELETE

func (r *Router) DELETE(pattern string, svc Service)

func (*Router) GET

func (r *Router) GET(pattern string, svc Service)

func (*Router) HEAD

func (r *Router) HEAD(pattern string, svc Service)

func (Router) Lookup

func (r Router) Lookup(method, path string) (Service, string, map[string]string, bool)

Lookup returns the Service, pattern, and extracted path parameters for the HTTP method and path.

func (*Router) OPTIONS

func (r *Router) OPTIONS(pattern string, svc Service)

func (*Router) PATCH

func (r *Router) PATCH(pattern string, svc Service)

func (*Router) POST

func (r *Router) POST(pattern string, svc Service)

func (*Router) PUT

func (r *Router) PUT(pattern string, svc Service)

func (Router) Params

func (r Router) Params(req Request) map[string]string

Params returns extracted path parameters, assuming the request has been routed and has captured parameters.

func (Router) Pattern

func (r Router) Pattern(req Request) string

Pattern returns the registered pattern which matches the given request.

func (*Router) Register

func (r *Router) Register(method, pattern string, svc Service)

func (Router) Serve

func (r Router) Serve() Service

func (*Router) TRACE

func (r *Router) TRACE(pattern string, svc Service)

type Service

type Service func(req *Request) Response

func (Service) Filter

func (svc Service) Filter(f Filter) Service

Jump to

Keyboard shortcuts

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