webmention

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidRequest = errors.New("the request does not contain a source and a target")

ErrInvalidRequest is returned by ExtractMention if either source or target are not provided or not URLs.

View Source
var ErrUnsupportedContentType = errors.New("application/x-www-form-urlencoded content-type required")

ErrUnsupportedContentType is returned by ExtractMention if the POST request is not form-urlencoded.

View Source
var ErrUnsupportedMethod = errors.New("unsupported HTTP method")

ErrUnsupportedMethod is returned by ExtractMention if a non-POST request is present.

Functions

func Verify

func Verify(ctx context.Context, mention *Mention, configurators ...func(c *VerifyOptions)) error

Verify uses a basic HTTP client and a default Verifier.

Types

type Document

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

func DocumentFromReader

func DocumentFromReader(ctx context.Context, reader io.Reader, u string) (*Document, error)

func DocumentFromURL

func DocumentFromURL(ctx context.Context, u string) (*Document, error)
func (d *Document) ExternalLinks() []string
func (d *Document) Links() []string

type EndpointDiscoverer

type EndpointDiscoverer interface {
	DiscoverEndpoint(ctx context.Context, url string) (string, error)
}

EndpointDiscoverer is used to discover the Webmention endpoint for the given URL.

func NewEndpointDiscoverer

func NewEndpointDiscoverer(configurators ...EndpointDiscoveryConfigurator) EndpointDiscoverer

NewEndpointDiscoverer creates a new EndpointDiscoverer configured with the given configurators.

type EndpointDiscoveryConfiguration

type EndpointDiscoveryConfiguration struct {
	HTTPClient *http.Client
}

EndpointDiscoveryConfiguration allows to pass configuration parameters to a new Discoverer.

type EndpointDiscoveryConfigurator

type EndpointDiscoveryConfigurator func(*EndpointDiscoveryConfiguration)

EndpointDiscoveryConfigurator is passed to NewEndDiscoverer to configure it.

type Mention

type Mention struct {
	Source     string
	Target     string
	Title      string
	Content    string
	AuthorName string
	Type       string
	RSVP       string
}

Mention is what is sent to a receiver linking source and target.

func ExtractMention

func ExtractMention(r *http.Request) (*Mention, error)

ExtractMention parses a given request object and tries to extract source and target from it.

type Sender

type Sender interface {
	// Send a webmention to the specified endpoint indicating that source
	// mentioned target.
	Send(ctx context.Context, endpoint string, mention Mention) error
}

Sender is used to send webmentions.

func NewSender

func NewSender(configurators ...SenderConfigurator) Sender

NewSender creates a configured sender implementation.

type SenderConfiguration

type SenderConfiguration struct {
	HTTPClient *http.Client
}

SenderConfiguration allows to inject a custom HTTP Client into the Sender.

type SenderConfigurator

type SenderConfigurator func(*SenderConfiguration)

SenderConfigurator is used as argument for the NewSender method and helps configuring a new Sender instance.

type Verifier

type Verifier interface {
	Verify(ctx context.Context, resp *http.Response, body io.Reader, mention *Mention) error
}

Verifier is used to check if a given response body produced by fetching mention.Source contains a link to mention.Target.

func NewVerifier

func NewVerifier() Verifier

NewVerifier creates a new verifier instance.

type VerifyOptions

type VerifyOptions struct {
	MaxRedirects int
}

Jump to

Keyboard shortcuts

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