multiplexer

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PubSubMetaSubscription is the meta attribute 'subscription' in the message root
	PubSubMetaSubscription PubSubMetaAttribute = "subscription"
	// PubSubMetaMessageID is the meta attribute in the 'message.messageId' path
	PubSubMetaMessageID = "message-id"
	// PubSubMetaPublishTime is the meta attribute in the 'message.publishTime' path
	PubSubMetaPublishTime = "publish-time"
)
View Source
const (
	// PubSubQueryToken is the query parameter in which the audience token is sent by Pub/Sub
	PubSubQueryToken = "token"
	// PubSubQueryAuthorization is the query parameter in which the authorization token is sent
	// by the Pub/Sub
	PubSubQueryAuthorization = "authorization"
)

Variables

View Source
var (
	// ErrNoHandlerFulfilled is returned if no provided handler can fulfill a request
	// accepted by the server. These errors can be avoided using default handlers such
	// as the HTTP HTTPHandler, which automatically fulfills all requests
	ErrNoHandlerFulfilled = errors.New("no handler was fulfilled for your request")
)

Functions

func InterceptPubSubRequest

func InterceptPubSubRequest(r *http.Request) (*http.Request, error)

InterceptPubSubRequest mutates the given http.Request, reading its body and converting it into the PubSub body. it also adds all PubSub metadata into headers, refills the body with the PubSub data, and corrects the Content-Length header

func IsGRPCRequest

func IsGRPCRequest(r *http.Request) bool

IsGRPCRequest returns true if the message is considered to be a GRPC message

func IsPubSubRequest

func IsPubSubRequest(r *http.Request) bool

IsPubSubRequest returns true if the given request is considered to be made by Google servers and thus pushed by Pub/Sub service

func Make

func Make(server *http2.Server, handlers ...Handler) http.Handler

Make creates a new multiplexer with given handlers. It combines all handlers to create a new h2c handler. If the server is not provided, a default http2 server will be created instead.

func PubSubAttributeHeader

func PubSubAttributeHeader(attr string) string

PubSubAttributeHeader returns a key for header access to the PubSub message attributes (PubSubMessage.Attributes)

func PubSubMetaAttributeHeader

func PubSubMetaAttributeHeader(attr PubSubMetaAttribute) string

PubSubMetaAttributeHeader creates a key for header access to the PubSUb meta information (see PubSubMetaAttribute)

func PubSubQueryHeader

func PubSubQueryHeader(param PubSubQueryParam) string

PubSubQueryHeader returns a key for header access to query parameters passed by the PubSub Request, such as token or Authorization

Types

type Handler

type Handler func(http.ResponseWriter, *http.Request) bool

Handler is a http.Handler that returns true/false based on if the request is being fulfilled by the handler or not

func GRPCHandler

func GRPCHandler(server http.Handler, selectors ...Selector) Handler

GRPCHandler fulfills requests that are considered to be grpc requests

func GRPCWebTextHandler

func GRPCWebTextHandler(server *grpcweb.WrappedGrpcServer, selectors ...Selector) Handler

GRPCWebTextHandler fulfills requests that are considered to be grpc web text requests

func HTTPHandler

func HTTPHandler(handler http.Handler, selectors ...Selector) Handler

HTTPHandler automatically fulfills all requests that come to its presence. This is because all non-http requests to an http server should be either redirected or fulfilled by other components in the way.

func PubSubHandler

func PubSubHandler(handler http.Handler, selectors ...Selector) Handler

PubSubHandler fulfills requests that are considered to be PubSub requests, automatically unwrapping their bodies and appending metadata as headers

type HandlerFactory

type HandlerFactory func(server http.Handler, selectors ...Selector) Handler

HandlerFactory is a function that implements wrapping a given http handler into a specific Handler

type PubSubMessage

type PubSubMessage struct {
	Data        []byte            `json:"data,omitempty"`
	Attributes  map[string]string `json:"attributes,omitempty"`
	MessageID   string            `json:"messageId,omitempty"`
	PublishTime string            `json:"publishTime,omitempty"`
	OrderingKey string            `json:"orderingKey,omitempty"`
}

PubSubMessage is a definition of the internal PubSub message received on PubSub push

type PubSubMetaAttribute

type PubSubMetaAttribute string

PubSubMetaAttribute are attributes known to be sent in the Pub/Sub wrapper.

example:

{
   "message": {
       "attributes": {
           "key": "value"
       },
       "data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
       "messageId": "136969346945"
		  "publishTime": "...."
   },
  "subscription": "projects/myproject/subscriptions/mysubscription"
}

subscription, message.messageId and publishTime are Meta attributes from this message sent by Pub/Sub

type PubSubQueryParam

type PubSubQueryParam string

PubSubQueryParam are query parameters known to be sent by the Pub/Sub push messages

type PushMessage

type PushMessage struct {
	Message      *PubSubMessage `json:"message,omitempty"`
	Subscription string         `json:"subscription,omitempty"`
}

PushMessage is a definition of the Google PubSub message received as a push message

type Selector

type Selector func(*http.Request) bool

Selector is a function that returns true if the request should be handled by the Handler is corresponds to

func OrSelector

func OrSelector(selectors ...Selector) Selector

OrSelector returns true if one of the selects is fulfilled

Jump to

Keyboard shortcuts

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