push

package module
v0.0.0-...-beec5d8 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

pubsub-push-middleware

Go Reference

Helper for handling GCP pubsub push messages in Go HTTP servers.

Why?

This middleware allows you to use your normal HTTP handlers with pubsub push messages. It does this by "promoting" the data in the pubsub push message to the HTTP request body. I use this with both RESTful and Twirp APIs. This allows me to use the same handlers for pubsub push without changing them.

Usage


import push "github.com/bakins/pubsub-push-middleware"

// assume handler is you normal HTTP handler.
mw := push.New(handler)

http.ListenAndServe(":8080", mw)

LICENSE

See LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultDetect

func DefaultDetect(r *http.Request, body []byte) bool

DefaultDetect checks if the body contains subscription and message json fields

func New

func New(next http.Handler, options ...Option) http.Handler

New creates HTTP middleware.

Types

type DetectFunc

type DetectFunc func(r *http.Request, body []byte) bool

DetectFunc detects if the request is a pubsub push request. Request will have already been tested to see if body is json and method is POST.

type Option

type Option func(*Options)

Option is a single option when creating middleware.

func WithDetector

func WithDetector(detect DetectFunc) Option

WithDetector sets the function to call to detect if the request body is a pubsub push request. If not set, DefaultDetect is used.

func WithPrefixes

func WithPrefixes(prefixes []string) Option

WithPrefixes sets the middleware to only run for the given prefixes. By default, all requests are checked. Prefixes are checked using simple string prefix checks.

type Options

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

Options define options when creating middleware.

Jump to

Keyboard shortcuts

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