Documentation
¶
Index ¶
- Constants
- Variables
- func ReloadHashDict(data []byte)
- func ViewHashDict() []byte
- type CacheClient
- func (c *CacheClient) Close()
- func (c *CacheClient) Delete(key string) error
- func (c *CacheClient) Exists(key string) bool
- func (c *CacheClient) Get(key string) (string, error)
- func (c *CacheClient) GetBytes(key string) ([]byte, error)
- func (c *CacheClient) GetEx(key string, expiration time.Duration) (string, error)
- func (c *CacheClient) GetKeys(keyPattern string, count ...int64) ([]string, error)
- func (c *CacheClient) Load(key string, value any) error
- func (c *CacheClient) MGet(keys []string) ([]any, error)
- func (c *CacheClient) PoolStats() *redis.PoolStats
- func (c *CacheClient) Save(key string, value any) error
- func (c *CacheClient) Set(key string, value any, expiration time.Duration) error
- func (c *CacheClient) Stats() *cache.Stats
- func (c *CacheClient) Store(key string, value any) error
- func (c *CacheClient) ValueExists(key string) bool
- func (c *CacheClient) ZAdd(key string, members []redis.Z) error
- func (c *CacheClient) ZRange(key string, start, stop int64) ([]string, error)
- func (c *CacheClient) ZRevRange(key string, start, stop int64) ([]string, error)
- type Feed
- type FeedURLs
- type FeedsMonitor
- func (fm *FeedsMonitor) FeedIndex(name string) int
- func (fm *FeedsMonitor) GetFeed(f *Feed)
- func (fm *FeedsMonitor) GetFromInstance(endpoint string, token ...string) ([]byte, error)
- func (fm *FeedsMonitor) LastCheck() int64
- func (fm *FeedsMonitor) LastCheckStr() string
- func (fm *FeedsMonitor) LastMonit() int64
- func (fm *FeedsMonitor) Location() *time.Location
- func (fm *FeedsMonitor) PostToInstance(req *fasthttp.Request) error
- func (fm *FeedsMonitor) SaveFeedsData() error
- func (fm *FeedsMonitor) Start()
- func (fm *FeedsMonitor) UpdateFollowers()
- type MastodonPost
- type Parser
Constants ¶
const DefaultCharacterLimit = 500 // default mastodon max character limit
const DefaultCheckInterval = 10 // default check feed interval in minutes
const DefaultUserAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36"
Variables ¶
var HashDictFile = "./hashdict.txt"
HashDictFile is the path to the external hash dictionary file used for hashtag translation. It maps raw strings extracted from item links (via HashLink regex) to their desired hashtag forms. Each line must be in the format: key=value (e.g. "krakow=Kraków" or "hokej-na-lodzie=HokejNaLodzie"). Lines starting with '#' are treated as comments and ignored. The file is loaded once at startup via init() and can be reloaded at runtime with ReloadHashDict.
Functions ¶
func ReloadHashDict ¶ added in v1.1.2
func ReloadHashDict(data []byte)
ReloadHashDict replaces the hash dictionary with the provided data. The data format is the same as the file format: key=value lines, with '#' as comment prefix. If data is nil, the file at HashDictFile is read. Calling ReloadHashDict is safe for concurrent use — reads are always lock-free. Typical use: reload after updating hashdict.txt at runtime without restarting.
func ViewHashDict ¶ added in v1.1.2
func ViewHashDict() []byte
ViewHashDict returns a copy of the current dictionary, in file format. The result is sorted by key.
Types ¶
type CacheClient ¶ added in v1.0.6
type CacheClient struct {
// contains filtered or unexported fields
}
CacheClient is a wrapper around the redis client and the cache library
var (
Cache *CacheClient = newCache()
)
Cache is the global cache client
func (*CacheClient) Close ¶ added in v1.1.0
func (c *CacheClient) Close()
Close closes the redis connection
func (*CacheClient) Delete ¶ added in v1.1.0
func (c *CacheClient) Delete(key string) error
Delete deletes a value from the cache for the given key
func (*CacheClient) Exists ¶ added in v1.0.6
func (c *CacheClient) Exists(key string) bool
Exists checks if a key exists in redis
func (*CacheClient) Get ¶ added in v1.0.6
func (c *CacheClient) Get(key string) (string, error)
Get gets a value from redis
func (*CacheClient) GetBytes ¶ added in v1.0.6
func (c *CacheClient) GetBytes(key string) ([]byte, error)
GetBytes gets a value from redis as bytes
func (*CacheClient) GetKeys ¶ added in v1.0.6
func (c *CacheClient) GetKeys(keyPattern string, count ...int64) ([]string, error)
GetKeys gets all keys matching a pattern
func (*CacheClient) Load ¶ added in v1.1.0
func (c *CacheClient) Load(key string, value any) error
Load retrieves a value from the cache for the given key and stores it in the value interface
func (*CacheClient) MGet ¶ added in v1.0.10
func (c *CacheClient) MGet(keys []string) ([]any, error)
MGet gets multiple values from redis
func (*CacheClient) PoolStats ¶ added in v1.1.0
func (c *CacheClient) PoolStats() *redis.PoolStats
PoolStats returns the redis connection pool statistics
func (*CacheClient) Save ¶ added in v1.1.0
func (c *CacheClient) Save(key string, value any) error
Save saves a value in the cache with the given key and a 2 year TTL
func (*CacheClient) Stats ¶ added in v1.1.0
func (c *CacheClient) Stats() *cache.Stats
Stats returns the cache statistics
func (*CacheClient) Store ¶ added in v1.1.0
func (c *CacheClient) Store(key string, value any) error
Store saves a value in the cache with the given key and a 7 day TTL
func (*CacheClient) ValueExists ¶ added in v1.1.0
func (c *CacheClient) ValueExists(key string) bool
ValueExists checks if a value exists in the cache for the given key
func (*CacheClient) ZAdd ¶ added in v1.0.10
func (c *CacheClient) ZAdd(key string, members []redis.Z) error
ZAdd adds members to a sorted set stored at key, creating the sorted set if it doesn't exist
type Feed ¶
type Feed struct {
Name string `yaml:"name"`
URLs FeedURLs `yaml:"url"`
Token string `yaml:"token"`
Prefix string `yaml:"prefix,omitempty"`
Visibility string `yaml:"visibility,omitempty"`
HashLink string `yaml:"hashlink,omitempty"`
HashTag string `yaml:"hashtag,omitempty"`
ReplaceFrom string `yaml:"replace_from,omitempty"`
ReplaceTo string `yaml:"replace_to,omitempty"`
ReplaceLink string `yaml:"replace_link,omitempty"`
Interval int64 `yaml:"interval,omitempty"`
LastRun int64 `yaml:"last_run,omitempty"`
Count int64 `yaml:"-"`
Id int64 `yaml:"-"`
Language string `yaml:"-"`
SendTime time.Time `yaml:"-"`
Followers atomic.Int64 `yaml:"-"`
// contains filtered or unexported fields
}
Feed holds the configuration and state for a single RSS feed The struct includes fields for: - Name: feed identifier/name - URLs: RSS feed endpoint(s); the first is primary, the rest are fallbacks - Token: Mastodon API access token - Prefix: optional text to prepend to posts - Visibility: post visibility level (public, unlisted, private) - HashLink: regex to extract a hashtag from the item link - HashTag: static hashtag always added to every post from this feed - ReplaceFrom/ReplaceTo: regex-based text replacement applied to post description - ReplaceLink: regex applied to item link — all matches are removed from the URL before posting - Interval: check interval in scheduler ticks - LastRun: Unix timestamp of last processed item - Count: number of items posted - Id: Mastodon account ID - Language: default language for posts from Mastodon profile - SendTime: time when last post was sent - Followers: concurrent follower count - shedCounter: scheduled counter for posting - etag: HTTP ETag for conditional requests
func NewTestFeed ¶ added in v1.1.0
NewTestFeed creates a new feed with default values for testing purposes This function is intended for testing and development purposes only
func (*Feed) EmptyEtag ¶ added in v1.1.4
func (f *Feed) EmptyEtag()
EmptyEtag initialises the etag to an empty slice. Must be called after URLs are set.
type FeedURLs ¶ added in v1.1.4
type FeedURLs []string
FeedURLs holds one or more RSS feed URLs with YAML unmarshaling support for both a single string ("url: https://...") and a list ("url:\n - https://..."). The first URL is the primary; subsequent URLs are used as fallbacks in order.
func (FeedURLs) MarshalYAML ¶ added in v1.1.4
MarshalYAML implements yaml.Marshaler so that a single-element FeedURLs is serialised back as a plain scalar (preserving the original YAML format).
type FeedsMonitor ¶
type FeedsMonitor struct {
// Instance holds the Mastodon instance configuration and list of feeds to monitor
// The struct includes fields for:
// - URL: Mastodon instance URL
// - Lang: default language for posts
// - Limit: maximum characters per post
// - TimeZone: timezone for date formatting
// - Save: whether to save state to disk
// - Monit: last monitoring run timestamp
// - Feeds: list of feeds to monitor
Instance struct {
URL string `yaml:"url"`
Lang string `yaml:"lang"`
Limit int `yaml:"limit"`
TimeZone string `yaml:"timezone"`
Save bool `yaml:"save,omitempty"`
Monit int64 `yaml:"last_monit,omitempty"`
Feeds []*Feed `yaml:"feed"`
} `yaml:"instance"`
Parser *Parser
// contains filtered or unexported fields
}
FeedsMonitor holds the configuration and state for monitoring multiple RSS feeds
func NewFeedsMonitor ¶
func NewFeedsMonitor() (*FeedsMonitor, error)
NewFeedsMonitor creates and initializes a new FeedsMonitor instance by: - Loading and parsing the feed configuration from YAML file - Setting up monitoring timestamps and intervals - Configuring timezone and language settings - Setting character limits and feed IDs - Initializing default values for all feeds
func (*FeedsMonitor) FeedIndex ¶ added in v1.0.6
func (fm *FeedsMonitor) FeedIndex(name string) int
FeedIndex returns the index of the feed with the given name prefix, or -1 if not found
func (*FeedsMonitor) GetFeed ¶ added in v1.1.0
func (fm *FeedsMonitor) GetFeed(f *Feed)
GetFeed retrieves and processes items from a feed For each item in the feed: - Checks if item is within time limits - Generates idempotency key based on item GUID - Skips if item already processed - Sanitizes title and description - Applies replacement rules if configured - Constructs message with title, description, hashtags and link - Sends post to mastodon instance - Updates counters and timestamps
func (*FeedsMonitor) GetFromInstance ¶ added in v1.1.0
func (fm *FeedsMonitor) GetFromInstance(endpoint string, token ...string) ([]byte, error)
GetFromInstance performs a GET request to the specified endpoint on the Mastodon instance. Optional parameter token can be provided for authentication
func (*FeedsMonitor) LastCheck ¶ added in v1.0.7
func (fm *FeedsMonitor) LastCheck() int64
LastCheck returns the Unix timestamp of the last check
func (*FeedsMonitor) LastCheckStr ¶ added in v1.0.7
func (fm *FeedsMonitor) LastCheckStr() string
LastCheckStr returns the formatted date/time string of the last check
func (*FeedsMonitor) LastMonit ¶ added in v1.0.6
func (fm *FeedsMonitor) LastMonit() int64
LastMonit returns the Unix timestamp of the last monitoring run
func (*FeedsMonitor) Location ¶ added in v1.0.6
func (fm *FeedsMonitor) Location() *time.Location
Location returns the timezone location used for time formatting
func (*FeedsMonitor) PostToInstance ¶ added in v1.1.0
func (fm *FeedsMonitor) PostToInstance(req *fasthttp.Request) error
PostToInstance performs a POST request to the Mastodon instance's API endpoint for creating statuses.
func (*FeedsMonitor) SaveFeedsData ¶
func (fm *FeedsMonitor) SaveFeedsData() error
SaveFeedsData saves the current feed monitoring state to the config file
func (*FeedsMonitor) Start ¶
func (fm *FeedsMonitor) Start()
Start processes all feeds in parallel using goroutines For each feed with valid URL and token: - Increments sheduler counter - When shedCounter reaches interval, resets counter and processes feed - Updates last check timestamp - Saves feed data if configured
func (*FeedsMonitor) UpdateFollowers ¶ added in v1.0.6
func (fm *FeedsMonitor) UpdateFollowers()
UpdateFollowers concurrently updates the follower counts for all feeds
type MastodonPost ¶ added in v1.1.0
type MastodonPost struct {
Status string `json:"status"`
Visibility string `json:"visibility"`
Language string `json:"language,omitempty"`
}
MastodonPost holds the data needed to post to Mastodon This struct is used to marshal the request body for posting to Mastodon API
type Parser ¶ added in v1.1.0
type Parser struct {
Client httpClient
// contains filtered or unexported fields
}
Parser wraps gofeed.Parser with an HTTP client and sync.Pool for efficient reuse
func NewParser ¶ added in v1.1.0
func NewParser(c httpClient) *Parser
NewParser creates a new RSS parser with optional custom HTTP client If no client is provided, a default fasthttp.Client is created with: - 1MB max response size - 15s read/write timeouts - 4096 concurrency limit - 1-hour DNS cache duration