hookrelay

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

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

Go to latest
Published: Oct 21, 2021 License: BSD-2-Clause Imports: 7 Imported by: 1

README

hookrelay

Minimal go library to relay webhook events back to an arbitrary service. With the use of a primary HTTP mux router, we are able to register endpoints (e.g., /hook) with a corresponding Response function to handle the aggregation of incoming requests.

First, there is a Hook interface we must satisfy by implementing it's functions for later usage.

type Hook interface {
	Response(i interface{}) func(w http.ResponseWriter, r *http.Request)
	LoadConfig(config string) error
	Endpoint() string
	Options() byte
}
  • Response: Contains the incoming webhook event request data and defines
    how to handle it.
  • LoadConfig: Used for any special configuration that may be used by
    the hook.
  • Endpoint: The endpoint path that events should be sent to.
  • Options: Optional middleware a hook may find useful, such as limiting
    the endpoint to only accept POST methods.

Examples can be found in the examples directory for practical usage and a better understanding. There is not a great deal behind this, and was more of a thin-wrapper to use in smaller sized, adhoc projects.

License

BSD 2-Clause

Documentation

Overview

* SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2021, Lewis Cook <lcook@FreeBSD.org> * All rights reserved.

* SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2021, Lewis Cook <lcook@FreeBSD.org> * All rights reserved.

* SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2021, Lewis Cook <lcook@FreeBSD.org> * All rights reserved.

Index

Constants

View Source
const (
	/*
	 * Check whether the incoming method is `POST`.
	 */
	OptionCheckMethod byte = 1 << iota
	/*
	 * Check whether the application type sent is `application/json`.
	 */
	OptionCheckType
	/*
	 * Reasonable defaults for webhook listening.
	 */
	DefaultOptions = (OptionCheckMethod | OptionCheckType)
)

* Optional middleware a hook can use for convenience.

Variables

This section is empty.

Functions

func InitMux

func InitMux(i interface{}, hooks []Hook, config, port string) (*http.Server, error)

Types

type Hook

type Hook interface {
	Response(i interface{}) func(w http.ResponseWriter, r *http.Request)
	LoadConfig(config string) error
	Endpoint() string
	Options() byte
}

Jump to

Keyboard shortcuts

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