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) (interface{}, 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 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 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"
RelationTypeActivityJSON identifies documents confirming to the Activity Streams 2.0 format. 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. }
Link represents a link, or relationship, to another resource on the Internet.
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")
Output:
func (*Link) GetPointer ¶ added in v0.10.1
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) 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
func NewLinkSet ¶ added in v0.8.0
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 searches for a matching link, updates it if found, and appends it if not
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
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 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 a pointer to the Resource so that calls can be chained.
func (Resource) Alias ¶
Alias adds an alias (additional URI) to this Resource. It returns a pointer to the 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