Documentation
¶
Index ¶
- Constants
- Variables
- func InterceptPubSubRequest(r *http.Request) (*http.Request, error)
- func IsGRPCRequest(r *http.Request) bool
- func IsPubSubRequest(r *http.Request) bool
- func Make(server *http2.Server, handlers ...Handler) http.Handler
- func PubSubAttributeHeader(attr string) string
- func PubSubMetaAttributeHeader(attr PubSubMetaAttribute) string
- func PubSubQueryHeader(param PubSubQueryParam) string
- type Handler
- func GRPCHandler(server http.Handler, selectors ...Selector) Handler
- func GRPCWebTextHandler(server *grpcweb.WrappedGrpcServer, selectors ...Selector) Handler
- func HTTPHandler(handler http.Handler, selectors ...Selector) Handler
- func PubSubHandler(handler http.Handler, selectors ...Selector) Handler
- type HandlerFactory
- type PubSubMessage
- type PubSubMetaAttribute
- type PubSubQueryParam
- type PushMessage
- type Selector
- type Server
Constants ¶
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" )
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 ¶
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 ¶
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 ¶
IsGRPCRequest returns true if the message is considered to be a GRPC message
func IsPubSubRequest ¶
IsPubSubRequest returns true if the given request is considered to be made by Google servers and thus pushed by Pub/Sub service
func Make ¶
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 ¶ added in v1.1.0
PubSubAttributeHeader returns a key for header access to the PubSub message attributes (PubSubMessage.Attributes)
func PubSubMetaAttributeHeader ¶ added in v1.1.0
func PubSubMetaAttributeHeader(attr PubSubMetaAttribute) string
PubSubMetaAttributeHeader creates a key for header access to the PubSUb meta information (see PubSubMetaAttribute)
func PubSubQueryHeader ¶ added in v1.1.0
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 ¶
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 ¶
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.
type HandlerFactory ¶ added in v1.2.0
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 ¶ added in v1.1.0
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 ¶ added in v1.1.0
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 ¶
Selector is a function that returns true if the request should be handled by the Handler is corresponds to
func OrSelector ¶
OrSelector returns true if one of the selects is fulfilled
type Server ¶ added in v1.3.0
type Server struct {
// contains filtered or unexported fields
}
Server wraps an implementation of a HTTP server with graceful shutdown
func NewServer ¶ added in v1.3.0
NewServer creates a new Server instance on the given port with the given timeout