Documentation ¶
Index ¶
- Variables
- func VerificationHandler(w http.ResponseWriter, r *http.Request)
- type WebhookEndpoint
- type WebhookEndpointDB
- type WebhookEndpointService
- type WebhookEndpointServiceImpl
- func (s *WebhookEndpointServiceImpl) Create(endpoint WebhookEndpoint) (WebhookEndpoint, error)
- func (s *WebhookEndpointServiceImpl) Delete(endpoint WebhookEndpoint) error
- func (s *WebhookEndpointServiceImpl) Get(endpoint WebhookEndpoint) (WebhookEndpoint, error)
- func (s *WebhookEndpointServiceImpl) LastNotificationSent(endpoint WebhookEndpoint) (WebhookNotification, error)
- func (s *WebhookEndpointServiceImpl) ListEndpoints() (*[]WebhookEndpoint, error)
- func (s *WebhookEndpointServiceImpl) Notify(endpoint WebhookEndpoint, notification WebhookNotification) error
- func (s *WebhookEndpointServiceImpl) UpdateURL(endpoint WebhookEndpoint) (WebhookEndpoint, error)
- func (s *WebhookEndpointServiceImpl) Verify(endpoint WebhookEndpoint) (WebhookEndpoint, error)
- type WebhookEndpointStatus
- type WebhookNotification
- type WebhookNotificationDB
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyEndpointURL error = errors.New(
`
cant accept an empty URL in an Endpoint declaration.
Recover by retrying with a non-empty URL in your Endpoint declaration
`,
)
var ErrEmptyEndpointURLScheme error = errors.New(
`
cant accept a URL without http/s.
you can recover by retrying with "https://"+endpoint
`,
)
var ErrEmptyEndpointUUID error = errors.New(
`
cant accept an empty UUID in an Endpoint.
Recover by retrying with a non-empty UUID in your Endpoint
`,
)
var ErrEndpointNotYetActivated error = errors.New(
`the endpoint youre trying to notify hasnt yet been activated.
recover by running service.Verify(endpoint) first`,
)
var ErrFailedEndpointVerification error = errors.New(
"failed to verify an endpoint",
)
var ErrFailedNotifyingTheEndpoint error = errors.New(
`the endpoint youre trying to notify returned an error.
This is perhaps an external issue, recovering might require
checking if the request body is parsed correctly and on both ends`,
)
var ErrIncorrectEndpointURL error = errors.New(
"cant accept a URL like this for verification",
)
var ErrIncorrectVerificationResponse error = errors.New(
"expected a different endpoint verification response",
)
var ErrInternalProcessingError error = errors.New(
`an internal error occured that shouldn't have happened.
Please submit an issue with as much detail as possible`,
)
var ErrRecordNotFound = errors.New(
`
Cant find the requested record,
Recover by retrying with a different identifier
or, where applicable, by enabling persistence.
`,
)
var ErrUnsupportedDatabaseEngine error = errors.New(
`
unsupported database engine.
Recover by retrying with either one of the documented database engines
`,
)
var ErrUnsupportedEndpointURLScheme error = errors.New(
"cant accept a URL without http/s for verification",
)
Functions ¶
func VerificationHandler ¶
func VerificationHandler(w http.ResponseWriter, r *http.Request)
Handles incoming Verification requests. To be used from the perspective of the webhook receiver.
Types ¶
type WebhookEndpoint ¶
type WebhookEndpoint struct { UUID uuid.UUID `json:"uuid"` URL string `json:"url"` Status WebhookEndpointStatus `json:"status"` }
type WebhookEndpointDB ¶
type WebhookEndpointService ¶
type WebhookEndpointService interface { Create(WebhookEndpoint) (WebhookEndpoint, error) UpdateURL(WebhookEndpoint) (WebhookEndpoint, error) Verify(WebhookEndpoint) (WebhookEndpoint, error) Get(WebhookEndpoint) (WebhookEndpoint, error) Delete(WebhookEndpoint) error Notify(WebhookEndpoint, WebhookNotification) error LastNotificationSent(WebhookEndpoint) (WebhookNotification, error) ListEndpoints() (*[]WebhookEndpoint, error) }
func NewWebhookService ¶
func NewWebhookService(custom_http_client *http.Client) (WebhookEndpointService, error)
Creates a new Webhook service, connects to a database and applies migrations
type WebhookEndpointServiceImpl ¶
type WebhookEndpointServiceImpl struct { WebhookEndpointService // contains filtered or unexported fields }
func (*WebhookEndpointServiceImpl) Create ¶
func (s *WebhookEndpointServiceImpl) Create(endpoint WebhookEndpoint) (WebhookEndpoint, error)
Creates a new unverified Webhook Endpoint. The next step would be to run the verification process on this endpoint.
verified_endpoint, err := service.Verify(endpoint)
Otherwise you will not be able to send Notifiations to the endpoint.
func (*WebhookEndpointServiceImpl) Delete ¶
func (s *WebhookEndpointServiceImpl) Delete(endpoint WebhookEndpoint) error
Deletes the indicated Endpoint
endpoint.UUID is used to find the webhook in the database.
func (*WebhookEndpointServiceImpl) Get ¶
func (s *WebhookEndpointServiceImpl) Get(endpoint WebhookEndpoint) (WebhookEndpoint, error)
Fetches the indicated Endpoint from the database
endpoint.UUID is used to find the webhook in the database.
func (*WebhookEndpointServiceImpl) LastNotificationSent ¶
func (s *WebhookEndpointServiceImpl) LastNotificationSent(endpoint WebhookEndpoint) (WebhookNotification, error)
func (*WebhookEndpointServiceImpl) ListEndpoints ¶
func (s *WebhookEndpointServiceImpl) ListEndpoints() (*[]WebhookEndpoint, error)
func (*WebhookEndpointServiceImpl) Notify ¶
func (s *WebhookEndpointServiceImpl) Notify(endpoint WebhookEndpoint, notification WebhookNotification) error
Notify sends a Notification to a verified Endpoint.
Notification's Topic and Body can be empty
func (*WebhookEndpointServiceImpl) UpdateURL ¶
func (s *WebhookEndpointServiceImpl) UpdateURL(endpoint WebhookEndpoint) (WebhookEndpoint, error)
Updates the endpoint with a new URL. The endpoint is then switched to Unverified so you will have to verify it again.
verified_endpoint, err := service.Verify(endpoint)
Otherwise you will not be able to send Notifiations to the endpoint.
endpoint.UUID is used to find the webhook in the database.
func (*WebhookEndpointServiceImpl) Verify ¶
func (s *WebhookEndpointServiceImpl) Verify(endpoint WebhookEndpoint) (WebhookEndpoint, error)
Verifies user's control over the provided endpoint. Runs a simple check to see if the endpoint responds with an expected answer.
given a request like below
<endpoint.URL>/verification?id=abcd
The verification process expects to see "abcd" in the response body.
type WebhookEndpointStatus ¶
type WebhookEndpointStatus int
const ( Unverified WebhookEndpointStatus = iota Suspended Verified Healthy )