gohooks

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: MIT Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultSignatureHeader = "X-GoHooks-Verification"
)

Variables

This section is empty.

Functions

func InjectRequestContext added in v2.1.0

func InjectRequestContext(span opentracing.Span, request *http.Request) error

func IsGoHookValid

func IsGoHookValid(data interface{}, signature, secret string) bool

IsGoHookValid checks the sha256 of the data matches the one given on the signature.

Types

type GoHook

type GoHook struct {
	// Data to be sent in the GoHook
	Payload GoHookPayload
	// The encrypted SHA resulting with the used salt
	ResultingSha string
	// Prepared JSON marshaled data
	PreparedData []byte
	// Choice of signature header to use on sending a GoHook
	SignatureHeader string
	// Should validate SSL certificate
	IsSecure bool
	// Preferred HTTP method to send the GoHook
	// Please choose only POST, DELETE, PATCH or PUT
	// Any other value will make the send use POST as fallback
	PreferredMethod string
	// Additional HTTP headers to be added to the hook
	AdditionalHeaders map[string]string
	// Span for distributed tracing
	Span *opentracing.Span
	// HTTP client Timeout in seconds (default 30)
	HTTPTimeout int64
	// HTTPUserAgent
	HTTPUserAgent string
}

GoHook represents the definition of a GoHook.

func (*GoHook) Create

func (hook *GoHook) Create(data interface{}, resource, secret string)

Create creates a webhook to be sent to another system, with a SHA 256 signature based on its contents.

func (*GoHook) CreateWithoutWrapper

func (hook *GoHook) CreateWithoutWrapper(data interface{}, secret string)

CreateCreateWithoutWrapper creates a webhook to be sent to another system, without wrapping it in a resource - data struct, with a SHA 256 signature based on its contents.

func (*GoHook) Send

func (hook *GoHook) Send(receiverURL string) (*http.Response, error)

Send sends a GoHook to the specified URL, as a UTF-8 JSON payload.

type GoHookPayload

type GoHookPayload struct {
	Resource string      `json:"resource"`
	Data     interface{} `json:"data"`
}

GoHookPayload represents the data that will be sent in the GoHook.

Jump to

Keyboard shortcuts

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