gocloud

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: BSD-3-Clause Imports: 12 Imported by: 1

README

go-webhookd-gocloud

Go package to implement the whosonfirst/go-webhookd interfaces for dispatching messages to gocloud.dev/blob resources.

Documentation

Go Reference

go-webhookd

Before you begin please read the go-webhookd documentation for an overview of concepts and principles.

Usage

import (
	_ "github.com/whosonfirst/go-webhookd-gocloud"
)

Example

import (
	_ "gocloud.dev/blob/memblob"
)

import (
	"context"
	"github.com/whosonfirst/go-webhookd/v3/dispatcher"
	_ "github.com/whosonfirst/go-webhookd-gocloud"
)

func main()

	ctx := context.Background()          
	d, _ := dispatcher.NewDispatcher(ctx, "mem://")
	
	d.Dispatch(ctx, []byte("hello world"))
}	

Error handling omitted for the sake of brevity.

See also

Documentation

Overview

package gocloud provides implementations of the whosonfirst/go-webhookd 'Dispatcher' interfaces for GoCloud resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashBody

func HashBody(ctx context.Context, body []byte) (string, error)

HashBody returns the hex-encoded SHA-256 sum of ' body'

func NewBlobDispatcher

func NewBlobDispatcher(ctx context.Context, uri string) (webhookd.WebhookDispatcher, error)

NewBlobDispatcher returns a new `BlobDispatcher` instance configured by 'uri' which is expected to be a valid and registered `gocloud.dev/blob.Bucket` URI. The following extra parameters are supported (and removed before the underelying bucket instance is created): - `?dispatch_prefix=_ts_` If present a unix timestamp will be prepended to the final filename.

func NewPubSubDispatcher added in v1.1.0

func NewPubSubDispatcher(ctx context.Context, uri string) (webhookd.WebhookDispatcher, error)

NewPubSubDispatcher returns a new `PubSubDispatcher` instance configured by 'uri' which is expected to be a valid and registered `gocloud.dev/pubsub.Topic` URI. The following extra parameters are supported (and removed before the underelying bucket instance is created):

  • `?mode={MODE}` An optional string describing how a message body should be processed and delivered to the pubsub topic. Valid options are 'all' which will deliver the entire message body in a single pubsub message or 'lines' which will deliver a separate pubsub message for each line in the (dispatch) message. Default is 'lines'.

Types

type BlobDispatcher

type BlobDispatcher struct {
	webhookd.WebhookDispatcher
	// contains filtered or unexported fields
}

BlobDispatcher implements the `webhookd.WebhookDispatcher` interface for dispatching messages to a gocloud.dev/blob.Bucket instance. Messages are written to the underlying bucket instance with a filename derived from the SHA-256 hash of the message body.

func (*BlobDispatcher) Dispatch

func (d *BlobDispatcher) Dispatch(ctx context.Context, body []byte) *webhookd.WebhookError

Dispatch will write 'body' to the underlying `gocloud.dev/blob.Bucket` instance contained by 'd'. Filenames are derived from the SHA-256 hash for 'body'.

type PubSubDispatcher added in v1.1.0

type PubSubDispatcher struct {
	webhookd.WebhookDispatcher
	// contains filtered or unexported fields
}

PubSubDispatcher implements the `webhookd.WebhookDispatcher` interface for dispatching messages to a `gocloud.dev/pubsub.Topic` instance.

func (*PubSubDispatcher) Dispatch added in v1.1.0

func (d *PubSubDispatcher) Dispatch(ctx context.Context, body []byte) *webhookd.WebhookError

Dispatch will write 'body' to the underlying `gocloud.dev/pubsub.Topic` instance contained by 'd'.

Jump to

Keyboard shortcuts

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