Documentation ¶
Index ¶
- Variables
- func CanonicalHref(href string) string
- func CreateAuthMiddleware(authInterceptor Interceptor, onUnauthorizedAccessFunc OnUnauthorizedAccessFunc) func(next netHttp.Handler) netHttp.Handler
- func CtxWithToken(ctx context.Context, token string) context.Context
- func ErrToStatus(err error) int
- func ErrToStatusWithDef(err error, def int) int
- func ProtobufContentType(s proto.Message) string
- func ReadErrorResponse(resp *fasthttp.Response) error
- func ReadRequest(p ProtoUnmarshaler, r *fasthttp.Request) error
- func ReadResponse(p ProtoUnmarshaler, r *fasthttp.Response) error
- func ReleaseRequestCtx(ctx *RequestCtx)
- func ToURLString(scheme string, host string, path string) string
- func TokenFromCtx(ctx context.Context) (string, error)
- func WriteErrorResponse(err error, resp *fasthttp.Response)
- func WriteRequest(p ProtoMarshaler, r *fasthttp.Request) error
- func WriteResponse(p ProtoMarshaler, r *fasthttp.Response) error
- type AuthArgs
- type Claims
- type ClaimsFunc
- type DeniedClaims
- type Interceptor
- type OnUnauthorizedAccessFunc
- type ProtoMarshaler
- type ProtoUnmarshaler
- type RequestCtx
- type RequestMatcher
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInternalServerError = errors.New("internal server error")
ErrInternalServerError internal server error
var TextPlainContentType = "text/plain; charset=utf-8"
TextPlainContentType content type strings for text plain that is user for error.
Functions ¶
func CreateAuthMiddleware ¶
func CreateAuthMiddleware(authInterceptor Interceptor, onUnauthorizedAccessFunc OnUnauthorizedAccessFunc) func(next netHttp.Handler) netHttp.Handler
CreateAuthMiddleware creates middleware for authorization
func ErrToStatusWithDef ¶
ErrToStatusWithDef converts err with default http.Status(for unknown conversion) to http.Status.
func ProtobufContentType ¶
ProtobufContentType content type strings for Protobuf.
Example ¶
var t TestRequest fmt.Println(ProtobufContentType(&t))
Output: application/protobuf; proto=http.test.TestRequest
func ReadErrorResponse ¶
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 ¶
ToURLString convert scheme, host, path to escaped url.
func WriteErrorResponse ¶
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 ClaimsFunc ¶
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 ¶
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 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 ¶
ProtoUnmarshaler defines methods for unmarshaling message to http
type RequestCtx ¶
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 ¶
RequestMatcher allows request without token validation.