digit

package module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 7 Imported by: 4

README

digit 👉

GoDoc Version Build Status Go Report Card Codecov

WebFinger for Go

Digit implements the WebFinger protocol. It includes type definitions for WebFinger data structures, along with some utilities for sending and receiving WebFinger requests

Generating WebFinger Data

Digit provides data types with a simple, chainable API for creating new resources.

resource := digit.NewResource("acct:sarah@sky.net").
	Alias("http://sky.net/sarah").
	Alias("http://other.website.com/sarah-connor").
	Property("http://sky.net/ns/role", "employee").
	Link(RelationTypeProfile, "text/html", "https://sky.net/sarah")

result, err := json.Marshal(resource)

Retrieving WebFinger Data

Digit can look up WebFinger metadata using a variety of identifiers

resource, err := digit.Lookup("sarah@sky.net") // Email construction
resource, err := digit.Lookup("sarah@sky.net") // Fediverse "@username" construction
resource, err := digit.Lookup("http://sky.net/sarah") // Canonical URL construction

WebFinger Resources

Pull Requests Welcome

Digit is relatively stable and is performing well in Emissary. However, it is still a work in progress, and will benefit from your experience reports, use cases, and contributions. If you have an idea for making this library better, send in a pull request. We're all in this together! 👉

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

Examples

Constants

View Source
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).

View Source
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

View Source
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.

View Source
const RelationTypeSelf = "self"

RelationTypeActivityJSON identifies documents confirming to the Activity Streams 2.0 format. See: https://www.w3.org/TR/activitystreams-core/#media-type

View Source
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

func ParseAccount(account string) []string

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 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.

func NewLink(relationType string, mediaType string, href string) Link

NewLink returns a fully initialized Link object.

func (*Link) GetPointer added in v0.10.1

func (link *Link) GetPointer(name string) (interface{}, bool)

func (Link) GetString added in v0.7.0

func (link Link) GetString(name string) string

func (Link) GetStringOK added in v0.9.0

func (link Link) GetStringOK(name string) (string, bool)

func (Link) IsEmpty added in v0.7.0

func (link Link) IsEmpty() bool

func (Link) Matches added in v0.8.0

func (link Link) Matches(otherLink Link) bool

Matches returns TRUE if the "otherLink" has the same type and rel as this link

func (Link) NotEmpty added in v0.10.5

func (link Link) NotEmpty() bool

func (Link) Property

func (link Link) Property(name string, value string) Link

Property populates a property of the link. Name must be a URI (called a property identifier) and value must be a string.

func (*Link) SetString added in v0.7.0

func (link *Link) SetString(name string, value string) bool

func (Link) Title

func (link Link) Title(title string, language string) Link

Title populates a title value for the Link.

type LinkSet added in v0.8.0

type LinkSet []Link

func NewLinkSet added in v0.8.0

func NewLinkSet(capacity int) LinkSet

func (*LinkSet) Append added in v0.8.0

func (set *LinkSet) Append(links ...Link)

Append adds a new link into the set without inspecting its contents

func (*LinkSet) Apply added in v0.8.0

func (set *LinkSet) Apply(link Link)

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

func (set *LinkSet) ApplyBy(name string, link Link)

ApplyBy searches for a matching link, updates it if found, and appends it if not

func (LinkSet) Find added in v0.8.0

func (set LinkSet) Find(link Link) Link

Find returns the first link that matches the provided link (having identical "rel" and "type" properties)

func (LinkSet) FindBy added in v0.8.0

func (set LinkSet) FindBy(name string, value string) Link

FindBy returns the first link with a property that matches the given value

func (*LinkSet) Remove added in v0.8.0

func (set *LinkSet) Remove(link Link)

Remove removes all items from the set that match the given link (having identical "rel" and "type" properties)

func (*LinkSet) RemoveBy added in v0.8.0

func (set *LinkSet) RemoveBy(name string, value string)

RemoveBy removes 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 Lookup added in v0.8.0

func Lookup(url string, options ...remote.Option) (Resource, error)

func NewResource

func NewResource(subject string) Resource

NewResource returns a fully initialized resource. The "subject" is a URI that identifies the entity.

func (resource Resource) AddLink(link Link) Resource

AddLink adds a link to this Resource. It returns a pointer to the Resource so that calls can be chained.

func (Resource) Alias

func (resource Resource) Alias(URI string) Resource

Alias adds an alias (additional URI) to this Resource. It returns a pointer to the Resource so that calls can be chained.

func (resource *Resource) FilterLinks(relationType string)

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 Resource) FindLink(relationType string) Link

FindLink searches links to find one that matches the provided relationType. If none is found, then an empty link is returned

func (resource Resource) Link(relationType string, mediaType string, href string) Resource

Link adds a link to this Resource. It returns a pointer to the Resource so that calls can be chained.

func (Resource) Property

func (resource Resource) Property(name string, value string) Resource

Property adds a property to this Resource. It returns a pointer to the Resource so that calls can be chained.

Jump to

Keyboard shortcuts

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