Documentation
¶
Overview ¶
Package activitypub provides ActivityPub protocol support for tens-city. It enables federation with Mastodon and other ActivityPub-compatible platforms.
Index ¶
- type Activity
- type Actor
- func (a *Actor) ClearPublished() error
- func (a *Actor) Config() *Config
- func (a *Actor) FetchActorInbox(actorURL string) (string, error)
- func (a *Actor) FollowersURL() string
- func (a *Actor) FollowingURL() string
- func (a *Actor) GetFediHandle() string
- func (a *Actor) GetFollowersCount() int
- func (a *Actor) GetPublishedCount() int
- func (a *Actor) HandleActor(w http.ResponseWriter, r *http.Request, username string)
- func (a *Actor) HandleActorLegacy(w http.ResponseWriter, r *http.Request, username string)
- func (a *Actor) HandleFollowers(w http.ResponseWriter, r *http.Request, username string)
- func (a *Actor) HandleFollowing(w http.ResponseWriter, r *http.Request, username string)
- func (a *Actor) HandleInbox(w http.ResponseWriter, r *http.Request, username string)
- func (a *Actor) HandleInboxLegacy(w http.ResponseWriter, r *http.Request, username string)
- func (a *Actor) HandleNodeInfo(w http.ResponseWriter, r *http.Request, localPosts int)
- func (a *Actor) HandleNodeInfoWellKnown(w http.ResponseWriter, r *http.Request)
- func (a *Actor) HandleOutbox(w http.ResponseWriter, r *http.Request, username string, posts []BlogPost)
- func (a *Actor) HandleWebFinger(w http.ResponseWriter, r *http.Request)
- func (a *Actor) ID() string
- func (a *Actor) InboxURL() string
- func (a *Actor) KeyID() string
- func (a *Actor) OutboxURL() string
- func (a *Actor) PublicKeyPEM() string
- func (a *Actor) PublishNewPosts(posts []BlogPost) (int, error)
- func (a *Actor) PublishPost(post BlogPost) ([]PublishResult, error)
- func (a *Actor) SignedGet(targetURL string) (*http.Response, error)
- func (a *Actor) SignedPost(targetURL string, body []byte) (*http.Response, error)
- type ActorEndpoints
- type ActorImage
- type ActorPublicKey
- type ActorResponse
- type Article
- type ArticleImage
- type BlogPost
- type Config
- type IncomingActivity
- type NodeInfo
- type NodeInfoLink
- type NodeInfoMetaSoftware
- type NodeInfoMetadata
- type NodeInfoServices
- type NodeInfoSoftware
- type NodeInfoUsage
- type NodeInfoUsers
- type NodeInfoWellKnown
- type OrderedCollection
- type PublishResult
- type Tag
- type WebFingerLink
- type WebFingerResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Activity ¶
type Activity struct {
Context string `json:"@context,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
Actor string `json:"actor"`
Published string `json:"published,omitempty"`
To []string `json:"to,omitempty"`
Cc []string `json:"cc,omitempty"`
Object interface{} `json:"object"`
}
Activity represents a generic ActivityPub activity
type Actor ¶
type Actor struct {
// contains filtered or unexported fields
}
Actor represents an ActivityPub actor
func NewActor ¶
NewActor creates a new ActivityPub actor with the given configuration. It loads or generates an RSA keypair for HTTP signatures.
func (*Actor) ClearPublished ¶
ClearPublished clears the published tracking (for testing/reset)
func (*Actor) FetchActorInbox ¶
FetchActorInbox fetches a remote actor and returns their inbox URL
func (*Actor) FollowersURL ¶
FollowersURL returns the actor's followers collection URL
func (*Actor) FollowingURL ¶
FollowingURL returns the actor's following collection URL
func (*Actor) GetFediHandle ¶ added in v0.8.2
GetFediHandle returns the actor's fediverse handle (e.g., @user@domain)
func (*Actor) GetFollowersCount ¶
GetFollowersCount returns the number of followers
func (*Actor) GetPublishedCount ¶
GetPublishedCount returns the number of published posts
func (*Actor) HandleActor ¶
HandleActor serves the ActivityPub actor profile. GET /users/{username} Content negotiation: returns JSON-LD for ActivityPub clients, HTML redirect otherwise
func (*Actor) HandleActorLegacy ¶
HandleActorLegacy handles requests to the legacy write.as/writefreely path. GET /api/collections/{username} Redirects to the canonical /users/{username} path
func (*Actor) HandleFollowers ¶
HandleFollowers serves the actor's followers collection. GET /users/{username}/followers
func (*Actor) HandleFollowing ¶
HandleFollowing serves the actor's following collection. GET /users/{username}/following
func (*Actor) HandleInbox ¶
HandleInbox handles incoming ActivityPub activities. POST /users/{username}/inbox
func (*Actor) HandleInboxLegacy ¶
HandleInboxLegacy handles requests to the legacy write.as/writefreely inbox path. POST /api/collections/{username}/inbox
func (*Actor) HandleNodeInfo ¶
HandleNodeInfo handles /nodeinfo/2.0 requests
func (*Actor) HandleNodeInfoWellKnown ¶
func (a *Actor) HandleNodeInfoWellKnown(w http.ResponseWriter, r *http.Request)
HandleNodeInfoWellKnown handles /.well-known/nodeinfo requests
func (*Actor) HandleOutbox ¶
func (a *Actor) HandleOutbox(w http.ResponseWriter, r *http.Request, username string, posts []BlogPost)
HandleOutbox serves the actor's outbox (published activities). GET /users/{username}/outbox
func (*Actor) HandleWebFinger ¶
func (a *Actor) HandleWebFinger(w http.ResponseWriter, r *http.Request)
HandleWebFinger handles WebFinger requests for actor discovery. GET /.well-known/webfinger?resource=acct:username@domain
func (*Actor) PublicKeyPEM ¶
PublicKeyPEM returns the public key in PEM format
func (*Actor) PublishNewPosts ¶
PublishNewPosts checks for posts that haven't been published yet and publishes them. Returns the number of posts published.
func (*Actor) PublishPost ¶
func (a *Actor) PublishPost(post BlogPost) ([]PublishResult, error)
PublishPost sends a Create activity for a blog post to all followers. Returns the number of successful deliveries and any errors.
type ActorImage ¶
type ActorImage struct {
Type string `json:"type"`
MediaType string `json:"mediaType,omitempty"`
URL string `json:"url"`
}
ActorImage represents an image attachment (icon, image)
type ActorPublicKey ¶
type ActorPublicKey struct {
ID string `json:"id"`
Owner string `json:"owner"`
PublicKeyPem string `json:"publicKeyPem"`
}
ActorPublicKey represents the actor's public key for HTTP signatures
type ActorResponse ¶
type ActorResponse struct {
Context interface{} `json:"@context"`
ID string `json:"id"`
Type string `json:"type"`
PreferredUsername string `json:"preferredUsername"`
Name string `json:"name"`
Summary string `json:"summary,omitempty"`
URL string `json:"url,omitempty"`
Inbox string `json:"inbox"`
Outbox string `json:"outbox"`
Followers string `json:"followers"`
Following string `json:"following"`
PublicKey ActorPublicKey `json:"publicKey"`
Icon *ActorImage `json:"icon,omitempty"`
Endpoints *ActorEndpoints `json:"endpoints,omitempty"`
}
ActorResponse represents an ActivityPub Actor object
type Article ¶
type Article struct {
ID string `json:"id"`
Type string `json:"type"`
AttributedTo string `json:"attributedTo"`
Name string `json:"name"`
Content string `json:"content"`
Summary string `json:"summary,omitempty"`
Published string `json:"published"`
Updated string `json:"updated,omitempty"`
URL string `json:"url"`
To []string `json:"to,omitempty"`
Cc []string `json:"cc,omitempty"`
Tag []Tag `json:"tag,omitempty"`
Image *ArticleImage `json:"image,omitempty"`
}
Article represents an ActivityPub Article object (for blog posts)
type ArticleImage ¶
type ArticleImage struct {
Type string `json:"type"`
MediaType string `json:"mediaType,omitempty"`
URL string `json:"url"`
Name string `json:"name,omitempty"`
}
ArticleImage represents an image attachment for an Article
type BlogPost ¶
type BlogPost struct {
ID string // Unique identifier (URL)
Slug string // URL slug
Title string // Post title
Description string // Short description/summary
Content string // HTML content
Published time.Time // Publication date
Updated time.Time // Last modified date (optional)
Tags []string // Post tags
AuthorName string // Author display name
Image string // Featured image URL (optional)
}
BlogPost represents a blog post for conversion to ActivityPub
type Config ¶
type Config struct {
// Actor identity
Username string // e.g., "myork"
Domain string // e.g., "blog.stackdump.com"
DisplayName string // e.g., "stackdump"
Summary string // Actor bio/description
// URLs
ProfileURL string // HTML profile page URL
IconURL string // Avatar/icon URL
// Key storage
KeyPath string // Path to store/load RSA private key
// Software info (for NodeInfo)
SoftwareName string
SoftwareVersion string
// NodeInfo metadata
NodeName string // e.g., "Stackdump Blog"
NodeDescription string // e.g., "Technical blog about..."
NodeHomePage string // e.g., "https://github.com/stackdump/tens-city"
NodeGitHub string // e.g., "https://github.com/stackdump/tens-city"
}
Config holds ActivityPub configuration for an actor
type IncomingActivity ¶
type IncomingActivity struct {
Context interface{} `json:"@context,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
Actor string `json:"actor"`
Object interface{} `json:"object"` // Can be string (for Follow) or object (for Create, etc.)
}
IncomingActivity represents an incoming ActivityPub activity
type NodeInfo ¶
type NodeInfo struct {
Version string `json:"version"`
Software NodeInfoSoftware `json:"software"`
Protocols []string `json:"protocols"`
Services NodeInfoServices `json:"services"`
Usage NodeInfoUsage `json:"usage"`
OpenRegistrations bool `json:"openRegistrations"`
Metadata NodeInfoMetadata `json:"metadata"`
}
NodeInfo represents the NodeInfo 2.0 schema response
type NodeInfoLink ¶
NodeInfoLink represents a link in the nodeinfo well-known response
type NodeInfoMetaSoftware ¶ added in v0.8.4
type NodeInfoMetaSoftware struct {
HomePage string `json:"homepage"`
GitHub string `json:"github"`
}
NodeInfoMetaSoftware has links about the software project
type NodeInfoMetadata ¶ added in v0.8.4
type NodeInfoMetadata struct {
NodeName string `json:"nodeName"`
NodeDescription string `json:"nodeDescription"`
Software NodeInfoMetaSoftware `json:"software"`
}
NodeInfoMetadata describes the node
type NodeInfoServices ¶ added in v0.8.4
type NodeInfoServices struct {
Inbound []string `json:"inbound"`
Outbound []string `json:"outbound"`
}
NodeInfoServices describes inbound/outbound service integrations
type NodeInfoSoftware ¶
NodeInfoSoftware describes the server software
type NodeInfoUsage ¶
type NodeInfoUsage struct {
Users NodeInfoUsers `json:"users"`
LocalPosts int `json:"localPosts"`
}
NodeInfoUsage describes server usage statistics
type NodeInfoUsers ¶
type NodeInfoUsers struct {
Total int `json:"total"`
ActiveMonth int `json:"activeMonth"`
ActiveHalfyear int `json:"activeHalfyear"`
}
NodeInfoUsers describes user statistics
type NodeInfoWellKnown ¶
type NodeInfoWellKnown struct {
Links []NodeInfoLink `json:"links"`
}
NodeInfoWellKnown represents the /.well-known/nodeinfo response
type OrderedCollection ¶
type OrderedCollection struct {
Context string `json:"@context"`
ID string `json:"id"`
Type string `json:"type"`
TotalItems int `json:"totalItems"`
OrderedItems []interface{} `json:"orderedItems,omitempty"`
First string `json:"first,omitempty"`
}
OrderedCollection represents an ActivityPub OrderedCollection
type PublishResult ¶
PublishResult tracks the result of publishing to a follower
type Tag ¶
type Tag struct {
Type string `json:"type"`
Name string `json:"name"`
Href string `json:"href,omitempty"`
}
Tag represents a hashtag or mention
type WebFingerLink ¶
type WebFingerLink struct {
Rel string `json:"rel"`
Type string `json:"type,omitempty"`
Href string `json:"href,omitempty"`
}
WebFingerLink represents a link in the WebFinger response
type WebFingerResponse ¶
type WebFingerResponse struct {
Subject string `json:"subject"`
Aliases []string `json:"aliases,omitempty"`
Links []WebFingerLink `json:"links"`
}
WebFingerResponse represents a WebFinger JRD response