Documentation
¶
Overview ¶
Package wikimediastreams provides functionality to receive notifications about changes on Wikimedia wikis, such as Wikipedia, using Server-Sent Events. See https://wikitech.wikimedia.org/wiki/EventStreams
Example usage:
var stream wikimediastreams.RecentChangesStream
// Optional configuration
// By default, you receive events from all wikis. Filter by wiki domain:
stream.FilterByDomain("en.wikipedia.org")
// or use a wildcard:
stream.FilterByDomain("*.wikipedia.org")
// If you had to reconnect but need to not miss any events, pass the
// last received event's Meta.DateTime to StartSince():
stream.StartSince("<last timestamp here>")
// To connect to some other, non-Wikimedia stream, use SetStreamURL():
stream.SetStreamURL("https://example.com/stream")
// End optional configuration
// Connect to the server and wait for events indefinitely.
err := stream.Run(func(event *wikimediastreams.RecentChangesEvent) {
fmt.Println(*event)
}, func(err error) {
fmt.Fprintln(os.Stderr, err)
})
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metadata ¶
type Metadata struct {
Domain string `json:"domain"`
DateTime string `json:"dt"`
ID string `json:"id"`
RequestID string `json:"request_id"`
SchemaURI string `json:"schema_uri"`
Topic string `json:"topic"`
URI string `json:"uri"`
Partition uint64 `json:"partition"`
Offset uint64 `json:"offset"`
}
Metadata represents metadata present in every stream type
type RecentChangesEvent ¶
type RecentChangesEvent struct {
Event
Bot bool `json:"bot"`
Comment string `json:"comment"`
Length newOldNumbers `json:"length"`
Minor bool `json:"minor"`
Namespace int `json:"namespace"`
Title string `json:"title"`
Patrolled bool `json:"patrolled"`
Revision newOldNumbers `json:"revision"`
Domain string `json:"server_name"`
Timestamp int `json:"timestamp"`
Type string `json:"type"`
LogType string `json:"log_type"`
User string `json:"user"`
Wiki string `json:"wiki"`
}
RecentChangesEvent contains information about recent changes
type RecentChangesStream ¶
type RecentChangesStream struct {
Stream
}
RecentChangesStream receives events about everything goin on in a wiki
func (*RecentChangesStream) Run ¶
func (s *RecentChangesStream) Run(receive func(*RecentChangesEvent), handleError func(error)) error
Run connects to the server and starts an infinite loop
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream is a base for type-specific streams
func (*Stream) FilterByDomain ¶
FilterByDomain allows to filter by domain. It can match both literal ("en.wikipedia.org") and masked ("*.wikibooks.org") domains. Does nothing after Run() has been called on the stream.
func (*Stream) SetStreamURL ¶
SetStreamURL allows to customize the URL to receive data from. Does nothing after Run() has been called on the stream.
func (*Stream) StartSince ¶
StartSince configures the stream to start reading events from some time in the past, represented by an ISO 8601 timestamp. Use it to avoid losing data on reconnects.
type UnexpectedSchemaError ¶
type UnexpectedSchemaError struct {
// contains filtered or unexported fields
}
UnexpectedSchemaError is returned when a message with an unexpected schema_uri is received
func (*UnexpectedSchemaError) Error ¶
func (e *UnexpectedSchemaError) Error() string