Documentation
¶
Overview ¶
Package digit provides a simple, chainable API that help you to generate webfinger objects, parse webfinger responses from external servers, and respond to webfinger queries to your own servers.
To use this package just populate a Resource object with all of the data you want to provide via your API, and then return the object to the caller.
Index ¶
- Constants
- func ParseAccount(account string) []string
- type Link
- func (link *Link) GetPointer(name string) (any, bool)
- func (link Link) GetString(name string) string
- func (link Link) GetStringOK(name string) (string, bool)
- func (link Link) IsEmpty() bool
- func (link Link) Matches(otherLink Link) bool
- func (link Link) NotEmpty() bool
- func (link Link) Property(name string, value string) Link
- func (link *Link) SetString(name string, value string) bool
- func (link Link) Title(title string, language string) Link
- type LinkSet
- func (set *LinkSet) Append(links ...Link)
- func (set *LinkSet) Apply(link Link)
- func (set *LinkSet) ApplyBy(name string, link Link)
- func (set LinkSet) Find(link Link) Link
- func (set LinkSet) FindBy(name string, value string) Link
- func (set *LinkSet) Remove(link Link)
- func (set *LinkSet) RemoveBy(name string, value string)
- type Resource
- func (resource Resource) AddLink(link Link) Resource
- func (resource Resource) Alias(URI string) Resource
- func (resource *Resource) FilterLinks(relationType string)
- func (resource Resource) FindLink(relationType string) Link
- func (resource Resource) Link(relationType string, mediaType string, href string) Resource
- func (resource Resource) Property(name string, value string) Resource
Examples ¶
Constants ¶
const RelationTypeAvatar = "https://webfinger.net/rel/avatar/"
RelationTypeAvatar identifies a person’s avatar and may be in any standard image format (e.g., PNG, JPEG, GIF).
const RelationTypeFEP3b86Prefix = "https://w3id.org/fep/3b86/"
RelationTypeFEP3b86Prefix is the prefix for FEP-3b86 interaction links. See: https://w3id.org/fep/3b86/
const RelationTypeHub = "hub"
RelationTypeHub is used by PubSubHubbub to identify the hub for a given resource. See: https://www.w3.org/TR/websub/#discovery See: https://pubsubhubbub.github.io/PubSubHubbub/pubsubhubbub-core-0.4.html#anchor4
const RelationTypeOpenIDIssuer = "http://openid.net/specs/connect/1.0/issuer"
RelationTypeOpenIDIssuer identifies the OpenID Connect issuer for a given resource, per the OpenID Connect Discovery specification.
const RelationTypeProfile = "https://webfinger.net/rel/profile-page/"
RelationTypeProfile identifies the main home/profile page that a human should visit when getting info about that webfinger account. It says nothing about the content-type (or microformats), but it’s likely text/html if it’s for users.
const RelationTypeSelf = "self"
RelationTypeSelf identifies the canonical Activity Streams 2.0 representation of the resource. See: https://www.w3.org/TR/activitystreams-core/#media-type
const RelationTypeSubscribeRequest = "http://ostatus.org/schema/1.0/subscribe"
RelationTypeSubscribeRequest is used by Mastodon to initiate a remote follow. See: https://www.hughrundle.net/how-to-implement-remote-following-for-your-activitypub-project/ See: http://ostatus.github.io/spec/OStatus%201.0%20Draft%202.html#anchor10
Variables ¶
This section is empty.
Functions ¶
func ParseAccount ¶ added in v0.11.0
ParseAccount returns a slice of potential WebFinger URLs for a given username. If the hostname is a localhost URL, then both HTTP and HTTPS versions are returned. Otherwise, only HTTPS endpoints are returned.
Types ¶
type Link ¶
type Link struct {
RelationType string `json:"rel,omitempty" bson:"rel,omitempty"` // Either a URI or a registered relation type (RFC5988)
MediaType string `json:"type,omitempty" bson:"type,omitempty"` // Media Type of the target resource (RFC 3986)
Href string `json:"href,omitempty" bson:"href,omitempty"` // URI of the target resource
Titles mapof.String `json:"titles,omitempty" bson:"titles,omitempty"` // Map keys are either language tag (or the string "und"), values are the title of this object in that language. If the language is unknown or unspecified, then the name is "und".
Properties mapof.String `json:"properties,omitempty" bson:"properties,omitempty"` // Zero or more name/value pairs whose names are URIs and whose values are strings. Properties are used to convey additional information about the link relationship.
Template string `json:"template,omitempty" bson:"template,omitempty"` // Non-standard URI template for the target resource (added by oStatus remote follows)
}
Link represents a link, or relationship, to another resource on the Internet. https://datatracker.ietf.org/doc/html/rfc7033#section-4.4.4
Example ¶
// Create a new link with a link relation, mime-type, and href
link := NewLink("http://webfinger.example/rel/profile-page", "text/html", "https://www.example.com/~bob")
// You can also set link titles in multiple languages
link = link.Title("en-us", "The Magical World of Steve")
link = link.Title("fr", "Le Mondo Magique de Steve")
func (*Link) GetPointer ¶ added in v0.10.1
GetPointer returns a pointer to the named map property ("titles" or "properties") of this Link, and a boolean that is TRUE when the property name is recognized.
func (Link) GetString ¶ added in v0.7.0
GetString returns the named string property of this Link, or "" if the name is not recognized.
func (Link) GetStringOK ¶ added in v0.9.0
GetStringOK returns the named string property of this Link, and a boolean that is TRUE when the property name is recognized.
func (Link) Matches ¶ added in v0.8.0
Matches returns TRUE if the "otherLink" has the same type and rel as this link
func (Link) NotEmpty ¶ added in v0.10.5
NotEmpty returns TRUE if the Link object has at least one value set.
func (Link) Property ¶
Property populates a property of the link. Name must be a URI (called a property identifier) and value must be a string.
type LinkSet ¶ added in v0.8.0
type LinkSet []Link
LinkSet is a collection of Links with helper methods for finding, applying, and removing links by their "rel" and "type" properties.
func NewLinkSet ¶ added in v0.8.0
NewLinkSet returns an empty LinkSet with the given pre-allocated capacity.
func (*LinkSet) Append ¶ added in v0.8.0
Append adds a new link into the set without inspecting its contents
func (*LinkSet) Apply ¶ added in v0.8.0
Apply searches for the first link that matches (with identical "rel" and "type" properties) the given link. If found, then the first matching item is updated. If not, then a new link is inserted
func (*LinkSet) ApplyBy ¶ added in v0.8.0
ApplyBy updates the first link whose named property matches the given link's, or appends the link if none match. It mutates the set in place.
func (LinkSet) Find ¶ added in v0.8.0
Find returns the first link that matches the provided link (having identical "rel" and "type" properties)
func (LinkSet) FindBy ¶ added in v0.8.0
FindBy returns the first link with a property that matches the given value
type Resource ¶
type Resource struct {
Subject string `json:"subject"` // REQUIRED: URI that identifies the entity.
Aliases []string `json:"aliases,omitempty"` // Zero or more URI strings that identify the same entity as the "subject" URI
Properties map[string]string `json:"properties,omitempty"` // Zero of more name/value pairs whose names are URIs and whose values are strings. Properties are used to convey additional information about the subject of the JRD.
Links []Link `json:"links,omitempty"` // Links to resources that are related or connected to this one.
}
Resource defines a single resource (such as a user or web page) that is being queried using the WebFinger protocol https://datatracker.ietf.org/doc/html/rfc7033#section-4.4
Example ¶
// Create and populate the resource object.
resource := NewResource("acct:sarah@sky.net").
Alias("http://sky.net/sarah").
Alias("http://linkedin.com/in/sarah-connor").
Property("http://sky.net/ns/role", "employee")
fmt.Print(resource.Subject)
Output: acct:sarah@sky.net
func Lookup ¶ added in v0.8.0
Lookup resolves a WebFinger account (a URL, an email-style handle, or a Fediverse address) into its Resource, querying each candidate endpoint until one succeeds. It returns an error if no endpoint can be reached.
func NewResource ¶
NewResource returns a fully initialized resource. The "subject" is a URI that identifies the entity.
func (Resource) AddLink ¶ added in v0.2.0
AddLink adds a link to this Resource. It returns the updated Resource so that calls can be chained.
func (Resource) Alias ¶
Alias adds an alias (additional URI) to this Resource. It returns the updated Resource so that calls can be chained.
func (*Resource) FilterLinks ¶ added in v0.6.0
FilterLinks updates the resource to only include links that match the provided relationType. If the provided relationType is empty, then no change is performed.
func (Resource) FindLink ¶ added in v0.2.0
FindLink searches links to find one that matches the provided relationType. If none is found, then an empty link is returned