Documentation
¶
Index ¶
- Constants
- Variables
- func NewLogger(name string) *logrus.Entry
- func NewPenguinRequest(resource string, params *url.Values) (*http.Request, error)
- func NewRetriedOperation(retryableFunc retry.RetryableFunc) error
- func UnmarshalFromReader(reader io.Reader, v interface{}) error
- func ValidServer(server string) bool
- type Cache
- type CacheConfig
- type UniString
- type Updater
Constants ¶
const AcceptableFailCount = 10
AcceptableFailCount describes how many fails would be tolerated until the server refuses to serve any more data
const (
// BaseEndpoint is the endpoint for all of the data
BaseEndpoint = "https://penguin-stats.io/PenguinStats/api/v2/"
)
const DefaultTimeout = time.Second * 20
DefaultTimeout describes the default timeout for the underlying http.Client that the updater uses
Variables ¶
var ( // ErrCacheNotFound describes a cache that cannot found with the server provided ErrCacheNotFound = errors.New("CacheNotFound", "cache not found with the server provided", errors.BlameUser) )
Functions ¶
func NewPenguinRequest ¶
NewPenguinRequest creates a http.Request that parses resource as relative path against BaseEndpoint to produce path, and appends server to the URL that is being generated
func NewRetriedOperation ¶
func NewRetriedOperation(retryableFunc retry.RetryableFunc) error
NewRetriedOperation executes a retry.RetryableFunc with custom default retry parameters. Returns error if all retry attempts failed
func UnmarshalFromReader ¶
UnmarshalFromReader unmarshals all data from reader and populates it to v
func ValidServer ¶
ValidServer validates if server counts as a valid server
Types ¶
type Cache ¶
type Cache struct { // Updated is to represent the last updated time Updated *time.Time // FailCount is the counter for how many times does the cache failed to update (after retries) FailCount int // == instance == // Name is the name of this cache instance Name string // Server is the server of this cache instance Server string // Interval is the update interval of cache Interval time.Duration // Client is the http.Client Client *http.Client // update is the function to update of underlying cache instance Updater Updater // Logger is the logger of such instance Logger *logrus.Entry // contains filtered or unexported fields }
Cache is the thread-safe cache instance that automatically updates data every Interval with Updater
func FindServerCache ¶
FindServerCache finds Cache that belongs to the specified server. Returns ErrCacheNotFound if not found.
func NewCache ¶
func NewCache(config CacheConfig) *Cache
NewCache creates a new Cache with CacheConfig provided
func (*Cache) Content ¶
func (c *Cache) Content() interface{}
Content retrieves the cache content with proper mutex handling
type CacheConfig ¶
type CacheConfig struct { // Name is the name of this cache instance Name string // Server is the server of this cache instance Server string // Interval is the update Interval of cache Interval time.Duration // Updater is the function to update of underlying cache instance Updater Updater }
CacheConfig describes the configuration to provide when initializing a cache instance
type UniString ¶
type UniString struct {
// contains filtered or unexported fields
}
UniString contains only unique strings which uses a underlying map which provides a constant time complexity
func NewUniString ¶
func NewUniString() *UniString
NewUniString creates a new UniString instance that contains only unique strings