httprule

package
v0.0.42 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentTypeBinaryProto = "application/x-protobuf"
	ContentTypeJSON        = "application/json"
)

Variables

This section is empty.

Functions

func Collect

func Collect(md protoreflect.MethodDescriptor) (rules []*annotations.HttpRule)

Collect any annotations.Rule entries from a proto method.

func DecodeRequest

func DecodeRequest(rule *annotations.HttpRule, pathVars map[string]string, req *http.Request, target proto.Message) error

DecodeRequest parses a http.Request, using a HttpRule, into a target message.

func HTTPStatusFromCode added in v0.0.27

func HTTPStatusFromCode(code codes.Code) int

HTTPStatusFromCode converts a gRPC error code into the corresponding HTTP response status. See: https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto

func MatchRequest

func MatchRequest(rule *annotations.HttpRule, req *http.Request) map[string]string

MatchRequest returns a non-nil map of extracted path vars if a http.Request matches a rule's request path and method.

Types

type Handler added in v0.0.37

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

Handler serves protobuf methods, annotated using httprule options, over HTTP.

func NewHandler added in v0.0.37

func NewHandler(files *registry.Files, handler grpc.StreamHandler, options ...Option) (*Handler, error)

NewHandler returns a new Handler that implements http.Handler that will dispatch HTTP requests matching the HttpRule annotations in the given registry. Requests that match a method are dispatched to the given gRPC handler.

func NewServer deprecated

func NewServer(files *registry.Files, handler grpc.StreamHandler, l log.Logger, httpRuleTemplates []*annotations.HttpRule) *Handler

NewServer returns a new Handler.

Deprecated: Use NewHandler instead. Handler used to be called Server.

func (*Handler) ServeHTTP added in v0.0.37

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Option added in v0.0.37

type Option func(h *Handler) error

Option is a function option for use with NewHandler.

func WithDefaultHandler added in v0.0.37

func WithDefaultHandler(next http.Handler) Option

WithDefaultHandler is an Option to configure a Handler with a fallback handler when the request being handled does not match any of the gRPC methods the Handler is configured with. By default the Handler will return a 404 NotFound response. If a default handler is supplied, it will be called instead of returning that 404 NotFound response.

func WithLogger added in v0.0.37

func WithLogger(l log.Logger) Option

WithLogger is an Option to configure a Handler with the given logger.

func WithRuleTemplates added in v0.0.37

func WithRuleTemplates(httpRuleTemplates []*annotations.HttpRule) Option

WithRuleTemplates is an Option to configure a Handler to provide a http rule template to be used for gRPC methods that do not have an HttpRule annotation.

type Server deprecated

type Server = Handler

Server is a Handler, and exists for backwards compatibility.

Deprecated: Use Handler instead.

Jump to

Keyboard shortcuts

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