webmention

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BaseUrl = "https://webmention.io/api/mentions.jf2" // API endpoint
View Source
var LoadFunc = LoadMentions
View Source
var ReadFileFunc = os.ReadFile
View Source
var SaveFunc = Save
View Source
var WriteFileFunc = os.WriteFile

Functions

func DoFetch

func DoFetch(ctx context.Context, client Client, mentionChannel chan Mention, worker Fetchable) error

func DoPersist

func DoPersist(fetchedMentions []Mention, s *sync.WaitGroup, persistable Persistable) error

func Save

func Save(filepath string, mentions []Mention) error

Save adds the current mention to a JSON file using provided io.Reader and io.Writer

Types

type Author

type Author struct {
	Type  string `json:"type" faker:"oneof: card"`
	Name  string `json:"name" faker:"name"`
	Photo string `json:"photo" faker:"url"`
	URL   string `json:"url" faker:"url"`
}

type Client

type Client struct {
	Domain   string
	Token    string
	SinceID  int
	PageSize int
	// contains filtered or unexported fields
}

func (*Client) GetMentions

func (client *Client) GetMentions() (*Response, error)

type Content

type Content struct {
	HTML string `json:"html" faker:"paragraph"`
	Text string `json:"text" faker:"paragraph"`
}

type FetchWorker

type FetchWorker struct {
	// contains filtered or unexported fields
}

func (*FetchWorker) AddObserver

func (fetchWorker *FetchWorker) AddObserver(observer MentionObserver)

func (*FetchWorker) AddObservers

func (fetchWorker *FetchWorker) AddObservers(observers []MentionObserver)

func (*FetchWorker) DoFetch

func (fetchWorker *FetchWorker) DoFetch(ctx context.Context, client Getter, mentionChannel chan<- Mention) error

DoFetch fetches mentions and sends them on mentionChannel until the source returns an empty response

type Fetchable

type Fetchable interface {
	DoFetch(context.Context, Getter, chan<- Mention) error
}

type FileReader

type FileReader interface {
	ReadFile(filepath string) ([]byte, error)
}

type FileWriter

type FileWriter interface {
	WriteFile(filepath string, data []byte, perm os.FileMode) error
}

FileWriter defines the WriteFile method for saving data to the filesystem.

type Getter

type Getter interface {
	GetMentions() (*Response, error)
}

type Loader

type Loader interface {
	LoadMentions(context.Context) ([]Mention, error)
}

type Mention

type Mention struct {
	Type       string    `json:"type" faker:"oneof: entry"`
	Author     Author    `json:"author"`
	URL        string    `json:"url" faker:"url"`
	Published  time.Time `json:"published"`
	WMReceived time.Time `json:"wm-received"`
	WMID       int       `json:"wm-id" faker:"unique"`
	WMSource   string    `json:"wm-source" faker:"url"`
	WMTarget   string    `json:"wm-target" faker:"url"`
	WMProtocol string    `json:"wm-protocol"`
	Name       string    `json:"name"`
	Content    Content   `json:"content"`
	InReplyTo  string    `json:"in-reply-to" faker:"url"`
	WMProperty string    `json:"wm-property" faker:"oneof: in-reply-to"`
	WMPrivate  bool      `json:"wm-private"`
}

func InsertMention

func InsertMention(mentions []Mention, mention Mention) []Mention

func LoadMentions

func LoadMentions(path string) ([]Mention, error)

func (*Mention) GenerateSlug

func (m *Mention) GenerateSlug() (string, error)

GenerateSlug creates a slug based on the WMTarget URL

type MentionObserver

type MentionObserver interface {
	Update(mention Mention)
}

type MetricsObserver

type MetricsObserver struct {
	MaxID            int
	EarliestReceived time.Time
	LatestReceived   time.Time
	AllSenders       []string
	MentionsSeen     int
	UniqueMentions   []int
	// contains filtered or unexported fields
}

func (*MetricsObserver) GetMetrics

func (m *MetricsObserver) GetMetrics() MetricsResponse

func (*MetricsObserver) Update

func (m *MetricsObserver) Update(mention Mention)

Update performs the necessary operations on an observed mention to main it's set of metrics.

type MetricsResponse

type MetricsResponse struct {
	MaxID            int
	EarliestReceived time.Time
	LatestReceived   time.Time
	AllSenders       []string
	MentionsSeen     int
	UniqueMentions   []int
}

type Persistable

type Persistable interface {
	DoPersist([]Mention, *sync.WaitGroup) error
}

type PersistenceWorker

type PersistenceWorker struct {
	// contains filtered or unexported fields
}

func (*PersistenceWorker) AddObserver

func (w *PersistenceWorker) AddObserver(observer MentionObserver)

func (*PersistenceWorker) DoPersist

func (w *PersistenceWorker) DoPersist(fetchedMentions []Mention, s *sync.WaitGroup) error

type Response

type Response struct {
	Type     string    `json:"type" faker:"oneof: 15, 16"`
	Name     string    `json:"name" faker:"oneof: entry"`
	Children []Mention `json:"children"`
}

Response Define structs based on the JSON structure

type Saver

type Saver interface {
	Save(filepath string, mentions []Mention) error
}

Jump to

Keyboard shortcuts

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