Documentation ¶
Index ¶
- Constants
- func AddImageToCache(data []byte) string
- func AddImageToCacheWithID(id string, data []byte)
- func AfterVoteImage() string
- func AlreadyDelegated() string
- func AlreadyVotedImage() string
- func ErrorImage(errorMessage string) (string, error)
- func FromCache(id string) []byte
- func InfoImage(infoLines []string) (string, error)
- func IsInCache(id string) bool
- func NotElegibleImage() string
- func NotFoundImage() string
- func NotificationsAcceptedImage() string
- func NotificationsDeniedImage() string
- func NotificationsErrorImage() string
- func NotificationsImage() string
- func NotificationsManageImage() string
- func Preview(election *api.Election) (string, error)
- func QuestionImage(election *api.Election) (string, error)
- func ResultsImage(election *api.Election, electiondb *mongo.Election, totalWeightStr string) (string, error)
- type ImageRequest
Constants ¶
const ( BackgroundNotificationsAccepted = "notifications-accepted.png" BackgroundNotificationsDenied = "notifications-denied.png" BackgroundNotifications = "notifications.png" BackgroundNotificationsError = "notifications-error.png" BackgroundNotificationsManage = "notifications-manage.png" BackgroundsDir = "images/" ImageGeneratorURL = "https://img.frame.vote" TimeoutImageGeneration = 15 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func AddImageToCache ¶
AddImageToCache adds an image to the LRU cache. Returns the cache key. The key is the hash of the image data.
func AddImageToCacheWithID ¶
AddImageToCacheWithID adds an image to the LRU cache with a specific ID.
func AfterVoteImage ¶
func AfterVoteImage() string
AfterVoteImage creates a static image to be displayed after a vote has been cast.
func AlreadyDelegated ¶
func AlreadyDelegated() string
AlreadyDelegated creates a static image to be displayed when a user has already delegated their vote.
func AlreadyVotedImage ¶
func AlreadyVotedImage() string
AlreadyVotedImage creates a static image to be displayed when a user has already voted.
func ErrorImage ¶
ErrorImage creates an image representing an error message.
func FromCache ¶
FromCache tries to retrieve data from cache with a specified id. Returns nil if the image is not in the cache. If the data is not available, it retries until the timeout is reached.
func InfoImage ¶
InfoImage creates an image displaying an informational message. Returns the image id that can be fetch using FromCache(id).
func NotElegibleImage ¶
func NotElegibleImage() string
NotElegibleImage creates a static image to be displayed when a user is not elegible to vote.
func NotFoundImage ¶
func NotFoundImage() string
NotFoundImage creates a static image to be displayed when an election is not found.
func NotificationsAcceptedImage ¶
func NotificationsAcceptedImage() string
NotificationsAcceptedImage creates a static image to be displayed when notifications are accepted.
func NotificationsDeniedImage ¶
func NotificationsDeniedImage() string
NotificationsDeniedImage creates a static image to be displayed when notifications are denied.
func NotificationsErrorImage ¶
func NotificationsErrorImage() string
NotificationsErrorImage creates a static image to be displayed when there is an error with notifications.
func NotificationsImage ¶
func NotificationsImage() string
NotificationsImage creates a static image to be displayed when notifications are requested.
func NotificationsManageImage ¶
func NotificationsManageImage() string
NotificationsManageImage creates a static image to be displayed when the user tries to manage muted users.
func QuestionImage ¶
QuestionImage creates an image representing a question with choices.
func ResultsImage ¶
func ResultsImage(election *api.Election, electiondb *mongo.Election, totalWeightStr string) (string, error)
ResultsImage creates an image showing the results of a poll. It returns the image id that can be fetch using FromCache(id). The totalWeightStr is the total weight of the census, if empty Turnout is not calculated. The electiondb is the election data from the database, if nil the participation is not calculated.
Types ¶
type ImageRequest ¶
type ImageRequest struct { Title string `json:"title,omitempty"` Type string `json:"type"` Error string `json:"error,omitempty"` Info []string `json:"info,omitempty"` Question string `json:"question,omitempty"` Choices []string `json:"choices,omitempty"` Results []string `json:"results,omitempty"` VoteCount uint64 `json:"voteCount"` Participation float32 `json:"participation"` Turnout float32 `json:"turnout"` Ends string `json:"ends,omitempty"` Ended bool `json:"ended,omitempty"` }
ImageRequest is a general struct for making requests to the API. It includes all possible fields that can be sent to the API.