http

package
v0.0.0-...-543d84f Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInternalServerError = errors.New("internal server error")

ErrInternalServerError internal server error

View Source
var TextPlainContentType = "text/plain; charset=utf-8"

TextPlainContentType content type strings for text plain that is user for error.

Functions

func CanonicalHref

func CanonicalHref(href string) string

CanonicalHref always lead by "/"

func CreateAuthMiddleware

func CreateAuthMiddleware(authInterceptor Interceptor, onUnauthorizedAccessFunc OnUnauthorizedAccessFunc) func(next netHttp.Handler) netHttp.Handler

CreateAuthMiddleware creates middleware for authorization

func CtxWithToken

func CtxWithToken(ctx context.Context, token string) context.Context

func ErrToStatus

func ErrToStatus(err error) int

ErrToStatus converts err to http.Status.

func ErrToStatusWithDef

func ErrToStatusWithDef(err error, def int) int

ErrToStatusWithDef converts err with default http.Status(for unknown conversion) to http.Status.

func ProtobufContentType

func ProtobufContentType(s proto.Message) string

ProtobufContentType content type strings for Protobuf.

Example
var t TestRequest
fmt.Println(ProtobufContentType(&t))
Output:

application/protobuf; proto=http.test.TestRequest

func ReadErrorResponse

func ReadErrorResponse(resp *fasthttp.Response) error

ReadErrorResponse validates the content type and decodes the body to the error.

func ReadRequest

func ReadRequest(p ProtoUnmarshaler, r *fasthttp.Request) error

ReadRequest validates the content type and decodes the body.

func ReadResponse

func ReadResponse(p ProtoUnmarshaler, r *fasthttp.Response) error

ReadResponse validates the content type and decodes the body.

func ReleaseRequestCtx

func ReleaseRequestCtx(ctx *RequestCtx)

ReleaseRequestCtx to release content. Be careful: you must copy all slices like body/headers that you want to use after ReleaseRequestCtx. Because they will be overridden by next AcquireRequestCtx.

func ToURLString

func ToURLString(scheme string, host string, path string) string

ToURLString convert scheme, host, path to escaped url.

func TokenFromCtx

func TokenFromCtx(ctx context.Context) (string, error)

func WriteErrorResponse

func WriteErrorResponse(err error, resp *fasthttp.Response)

WriteErrorResponse sets the content type and encodes the error to the body.

func WriteRequest

func WriteRequest(p ProtoMarshaler, r *fasthttp.Request) error

WriteRequest sets the content type and encodes the body.

func WriteResponse

func WriteResponse(p ProtoMarshaler, r *fasthttp.Response) error

WriteResponse sets the content type and encodes the body.

Types

type AuthArgs

type AuthArgs struct {
	URI    *regexp.Regexp
	Scopes []*regexp.Regexp
}

type Claims

type Claims = interface{ Valid() error }

type ClaimsFunc

type ClaimsFunc = func(ctx context.Context, method, uri string) Claims

func MakeClaimsFunc

func MakeClaimsFunc(methods map[string][]AuthArgs) ClaimsFunc

type DeniedClaims

type DeniedClaims struct {
	Err error
}

func (DeniedClaims) Valid

func (c DeniedClaims) Valid() error

type Interceptor

type Interceptor = func(ctx context.Context, method, uri string) (context.Context, error)

func NewInterceptor

func NewInterceptor(jwksURL string, tls *tls.Config, auths map[string][]AuthArgs, whiteList ...RequestMatcher) Interceptor

NewInterceptor authorizes HTTP request.

func ValidateJWT

func ValidateJWT(jwksURL string, tls *tls.Config, claims ClaimsFunc) Interceptor

type OnUnauthorizedAccessFunc

type OnUnauthorizedAccessFunc = func(ctx context.Context, w netHttp.ResponseWriter, r *netHttp.Request, err error)

type ProtoMarshaler

type ProtoMarshaler interface {
	proto.Message
	Size() int
	Marshal() ([]byte, error)
	MarshalTo(data []byte) (int, error)
}

ProtoMarshaler defines methods for marshaling message to http

type ProtoUnmarshaler

type ProtoUnmarshaler interface {
	proto.Message
	Unmarshal(data []byte) error
}

ProtoUnmarshaler defines methods for unmarshaling message to http

type RequestCtx

type RequestCtx struct {
	Req  *fasthttp.Request
	Resp *fasthttp.Response
}

RequestCtx provides http methods: POST. It is used to send a single request and obtain the response.

func AcquireRequestCtx

func AcquireRequestCtx() *RequestCtx

AcquireRequestCtx along with ReleaseRequestCtx are used to manage the lifetime of the enclosed pooled data structures.

func (*RequestCtx) PostProto

func (ctx *RequestCtx) PostProto(client *fasthttp.Client, uri string, in ProtoMarshaler, out ProtoUnmarshaler) (int, error)

PostProto posts a protobuf message to an HTTP server and receives a protobuf response on fasthttp.StatusOK.

type RequestMatcher

type RequestMatcher struct {
	Method string
	URI    *regexp.Regexp
}

RequestMatcher allows request without token validation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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