apub

package module
v0.0.0-...-45bcd63 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2018 License: Zlib Imports: 21 Imported by: 0

README

activity pub library for go

status: not done

Documentation

Index

Constants

View Source
const ContentType = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"`

ContentType is the mimetype for activitypub

Variables

This section is empty.

Functions

This section is empty.

Types

type APubHandler

type APubHandler struct {
	Database Database // Database must not be nil
	// contains filtered or unexported fields
}

APubHandler

func (*APubHandler) SetupRoutes

func (a *APubHandler) SetupRoutes(setupRoute func(string, http.Handler), setupSubRouter func(string, http.Handler))

SetupRoutes sets up routes

type Database

type Database interface {

	// return the local server's hostname
	LocalHost() string

	// LocalUser gets a local user by username
	// returns user, nil on found
	// returns nil, nil on not found
	// returns nil, error on db error
	LocalUser(username string) (User, error)

	// LocalPost gets a local post by post id
	// returns post, nil on post found
	// returns nil, nil on post not found
	// returns nil, error on db error
	LocalPost(postid string) (*Post, error)

	// LocalUserPosts gets a slice of posts of a user by name with offset and limit
	// posts may be empty
	// retruns posts, nil on success
	// returns nil, err on db error
	LocalUserPosts(username string, offset int64, limit int) ([]*Post, error)

	ListFollowers(username string) ([]User, error)
	ListFollowing(username string) ([]User, error)
}

Database defines an interface for interacting with a persistant datastore for posts and user information

type InfoFinder

type InfoFinder interface {
	// returns nil, nil on not found
	// returns url, nil on found
	// returns nil, error on error
	LocalUser(string) (*UserInfo, error)

	// list all users that follow a user by local username
	ListFollowers(string) ([]*UserInfo, error)

	// list all users that a local users follows by local username
	ListFollowing(string) ([]*UserInfo, error)
}

InfoFinder finds a UserInfo given a string

type Post

type Post struct {
	Message string
	To      RecipInfo
	From    string
	Posted  time.Time
	Updated time.Time
	Feed    string
	Self    string
}

func (*Post) FeedURL

func (p *Post) FeedURL() string

func (*Post) HTML

func (p *Post) HTML() string

func (*Post) MarshalXML

func (p *Post) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (*Post) Mentions

func (p *Post) Mentions() []string

func (*Post) PostURL

func (p *Post) PostURL() string

func (*Post) PostedAt

func (p *Post) PostedAt() time.Time

func (*Post) Text

func (p *Post) Text() string

func (*Post) UnmarshalXML

func (p *Post) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type RecipInfo

type RecipInfo struct {
	Users []string
}

type User

type User = apub.User

type UserInfo

type UserInfo struct {
	ServerName   string // server name
	UserName     string // username without '@'
	PreferedName string // prefered name

	Summary string // profile summary
	Avatar  string // avatar url
	Header  string // header url

	SigningKey *rsa.PrivateKey // rsa private signing key

	Profile string // profile url
	Inbox   string // inbox url
	Outbox  string // outbox url
	Feed    string // atom feed url

	GetPosts       func(offset int64, limit int) ([]*Post, error)
	GetLastUpdated func() time.Time
}

local user implements apub.User

func (*UserInfo) AtomFeedURL

func (info *UserInfo) AtomFeedURL() string

func (*UserInfo) InboxURL

func (info *UserInfo) InboxURL() string

func (*UserInfo) LastUpdated

func (info *UserInfo) LastUpdated() time.Time

func (*UserInfo) LoadPrivateKey

func (info *UserInfo) LoadPrivateKey(pemStr string) (err error)

func (*UserInfo) MarshalJSON

func (info *UserInfo) MarshalJSON() ([]byte, error)

func (*UserInfo) OutboxURL

func (info *UserInfo) OutboxURL() string

func (*UserInfo) Posts

func (info *UserInfo) Posts(offset int64, limit int) (posts []apub.Post, err error)

func (*UserInfo) ProfileURL

func (info *UserInfo) ProfileURL() string

func (*UserInfo) RegenerateSigningKey

func (info *UserInfo) RegenerateSigningKey() (err error)

func (*UserInfo) Sign

func (info *UserInfo) Sign(r io.Reader) (sig, hash []byte, err error)

sign data using rsa / sha256

func (*UserInfo) ToAtomFeed

func (info *UserInfo) ToAtomFeed(title string, nextURL string) (f apub.UserFeed, err error)

func (*UserInfo) User

func (info *UserInfo) User() string

func (*UserInfo) WebFingerAlias

func (info *UserInfo) WebFingerAlias() string
func (info *UserInfo) WebFingerLinks() (links []apub.Link)

func (*UserInfo) WebFingerSubject

func (info *UserInfo) WebFingerSubject() string

type UserName

type UserName string

UserName is the @user@host

func NormalizeUser

func NormalizeUser(str, ourserver string) UserName

NormalizeUser converts a string into a UserName given our local server name

func (UserName) Server

func (u UserName) Server() string

server part

func (UserName) String

func (u UserName) String() string

func (UserName) User

func (u UserName) User() string

user part

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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