Documentation ¶
Index ¶
- Variables
- func ContainsID(a []uint64, x uint64) bool
- func WrapError(err error, annotators ...fail.Annotator) error
- type Contest
- type ContestID
- type ContestLanguageStat
- type ContestLog
- type ContestLogView
- type ContestLogs
- type ContestStats
- type Contests
- type Environment
- type Language
- type LanguageCode
- type LanguageCodes
- type Languages
- type Medium
- type MediumID
- type Mediums
- type Preferences
- type Ranking
- type RankingRegistration
- type RankingView
- type Rankings
- type Role
- type User
- type Users
Constants ¶
This section is empty.
Variables ¶
var AllEnvironments = []Environment{ EnvProduction, EnvDevelopment, EnvTest, }
AllEnvironments a collection of all valid environments
var AllLanguageCodes = LanguageCodes{ Global, Arabic, Chinese, Croatian, Czech, Dutch, Esperanto, English, Finnish, French, German, Greek, Hebrew, Hungarian, Irish, Italian, Japanese, Korean, Latin, Polish, Portuguese, Russian, Spanish, Swedish, Thai, Tagalog, Turkish, }
AllLanguageCodes is an array with all possible language codes
var AllLanguages = Languages{ Language{Code: Arabic, Name: "Arabic"}, Language{Code: Chinese, Name: "Chinese"}, Language{Code: Croatian, Name: "Croatian"}, Language{Code: Czech, Name: "Czech"}, Language{Code: Dutch, Name: "Dutch"}, Language{Code: Esperanto, Name: "Esperanto"}, Language{Code: English, Name: "English"}, Language{Code: Finnish, Name: "Finnish"}, Language{Code: French, Name: "French"}, Language{Code: German, Name: "German"}, Language{Code: Greek, Name: "Greek"}, Language{Code: Hebrew, Name: "Hebrew"}, Language{Code: Hungarian, Name: "Hungarian"}, Language{Code: Irish, Name: "Irish"}, Language{Code: Italian, Name: "Italian"}, Language{Code: Japanese, Name: "Japanese"}, Language{Code: Korean, Name: "Korean"}, Language{Code: Latin, Name: "Latin"}, Language{Code: Polish, Name: "Polish"}, Language{Code: Portuguese, Name: "Portuguese"}, Language{Code: Russian, Name: "Russian"}, Language{Code: Spanish, Name: "Spanish"}, Language{Code: Swedish, Name: "Swedish"}, Language{Code: Thai, Name: "Thai"}, Language{Code: Tagalog, Name: "Tagalog"}, Language{Code: Turkish, Name: "Turkish"}, }
AllLanguages is an array with all possible languages
var AllMediums = Mediums{ MediumBook: Medium{Description: "Book", Points: 1}, MediumComic: Medium{Description: "Comic", Points: 0.2}, MediumNet: Medium{Description: "Net", Points: 1}, MediumFullGame: Medium{Description: "Full game", Points: 0.1667}, MediumGame: Medium{Description: "Game", Points: 0.05}, MediumLyric: Medium{Description: "Lyric", Points: 1}, MediumNews: Medium{Description: "News", Points: 1}, MediumSentences: Medium{Description: "Sentences", Points: 0.05}, }
AllMediums is an array with all existing media
var ErrContestInvalidDateOrder = fail.New("contest must start before it can end")
ErrContestInvalidDateOrder for when you accidentally switch up the starting and ending dates
var ErrContestInvalidDateTooOld = fail.New("contest must end in the future")
ErrContestInvalidDateTooOld for when you try to make a contest that has already ended
var ErrInsufficientPermissions = fail.New("need higher permissions for this resource")
ErrInsufficientPermissions for when access to a resource is denied
var ErrInvalidEnvironment = fail.New("supplied environment is not supported")
ErrInvalidEnvironment for when an environment is not defined in our app
var ErrInvalidLanguage = fail.New("supplied language is not supported")
ErrInvalidLanguage for when a language is not defined in our app
var ErrMediumNotFound = fail.New("medium does not exist")
ErrMediumNotFound for when a given medium id does not exist
var ErrNotFound = sql.ErrNoRows
ErrNotFound for when an entity could not be found
var ErrPasswordIncorrect = fail.New("invalid password supplied")
ErrPasswordIncorrect for when an invalid password is given
Functions ¶
func ContainsID ¶
ContainsID returns wether or not an ID can be found in the array
Types ¶
type Contest ¶
type Contest struct { ID uint64 `json:"id" db:"id"` Description string `json:"description" db:"description" valid:"required"` Start time.Time `json:"start" db:"start" valid:"required"` End time.Time `json:"end" db:"end" valid:"required"` Open bool `json:"open" db:"open"` }
Contest contains the data about when a contest is being held
type ContestID ¶
type ContestID uint64
ContestID is a container for contest ids with some domain logic
type ContestLanguageStat ¶
type ContestLog ¶
type ContestLog struct { ID uint64 `json:"id" db:"id"` ContestID uint64 `json:"contest_id" db:"contest_id" valid:"required"` UserID uint64 `json:"user_id" db:"user_id" valid:"required"` Language LanguageCode `json:"language_code" db:"language_code" valid:"required"` MediumID MediumID `json:"medium_id" db:"medium_id" valid:"required"` Amount float32 `json:"amount" db:"amount" valid:"required"` Description string `json:"description" db:"description"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` DeletedAt *time.Time `json:"deleted_at" db:"deleted_at"` // Optional embedded records UserDisplayName string `db:"user_display_name"` }
ContestLog contains a single entry in a contest for a user
func (ContestLog) AdjustedAmount ¶
func (c ContestLog) AdjustedAmount() float32
AdjustedAmount gives the amount after having taken into account the medium
func (ContestLog) GetView ¶
func (c ContestLog) GetView() ContestLogView
GetView gets the external view representation of a contest log
type ContestLogView ¶
type ContestLogView struct { ID uint64 `json:"id"` ContestID uint64 `json:"contest_id"` UserID uint64 `json:"user_id"` Language LanguageCode `json:"language_code"` MediumID MediumID `json:"medium_id"` Amount float32 `json:"amount"` AdjustedAmount float32 `json:"adjusted_amount"` Description string `json:"description"` Date time.Time `json:"date"` UserDisplayName string `json:"user_display_name,omitempty"` }
ContestLogView is a representation of a contest log for external usages
type ContestLogs ¶
type ContestLogs []ContestLog
ContestLogs is a collection of ContestLog
func (ContestLogs) GetView ¶
func (c ContestLogs) GetView() []ContestLogView
GetView gets the external view representation of a contest log collection
type ContestStats ¶
type ContestStats struct { ByLanguage []ContestLanguageStat `json:"by_language"` Participants int `json:"participants"` TotalAmount float64 `json:"total_amount"` }
type Environment ¶
type Environment string
Environment of the app
const ( EnvProduction Environment = "production" EnvDevelopment Environment = "development" EnvTest Environment = "test" )
Environment enum
func (Environment) ShouldSecure ¶
func (env Environment) ShouldSecure() bool
ShouldSecure indicates wether or not the environment needs to have security enforced
func (Environment) Validate ¶
func (env Environment) Validate() error
Validate wether or the the environment is a valid one
type Language ¶
type Language struct { Code LanguageCode Name string }
Language contains a language Name and code
type LanguageCode ¶
type LanguageCode string
LanguageCode according to ISO 639-3
const ( Global LanguageCode = "GLO" // This is uppercase so it wouldn't collide with Galambu Arabic LanguageCode = "ara" Chinese LanguageCode = "zho" Croatian LanguageCode = "hrv" Czech LanguageCode = "ces" Dutch LanguageCode = "nld" English LanguageCode = "eng" Esperanto LanguageCode = "epo" Finnish LanguageCode = "fin" French LanguageCode = "fra" German LanguageCode = "deu" Greek LanguageCode = "ell" Hebrew LanguageCode = "heb" Hungarian LanguageCode = "hun" Irish LanguageCode = "gle" Italian LanguageCode = "ita" Japanese LanguageCode = "jpn" Korean LanguageCode = "kor" Latin LanguageCode = "lat" Polish LanguageCode = "pol" Portuguese LanguageCode = "por" Russian LanguageCode = "rus" Spanish LanguageCode = "spa" Swedish LanguageCode = "swe" Thai LanguageCode = "tha" Tagalog LanguageCode = "tgl" Turkish LanguageCode = "tur" )
These are all the possible values for LanguageCode This list is not yet complete, it's just a start Language codes from: https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Languages/List_of_ISO_639-3_language_codes_(2019)
func (LanguageCode) Validate ¶
func (code LanguageCode) Validate() (bool, error)
Validate a language code
type LanguageCodes ¶
type LanguageCodes []LanguageCode
LanguageCodes is a collection of language codes
func (LanguageCodes) ContainsLanguage ¶
func (codes LanguageCodes) ContainsLanguage(target LanguageCode) bool
ContainsLanguage is a helper to figure out if a collection of languages contains the target language
func (LanguageCodes) Len ¶
func (codes LanguageCodes) Len() int
Len is the number of elements in the collection.
func (LanguageCodes) Less ¶
func (codes LanguageCodes) Less(i, j int) bool
Less reports whether the element with index i should sort before the element with index j.
func (LanguageCodes) Swap ¶
func (codes LanguageCodes) Swap(i, j int)
Swap swaps the elements with indexes i and j.
type Medium ¶
type Medium struct { Description string `json:"description" db:"description"` Points float32 `json:"points" db:"points"` }
Medium knows how the score for a medium should be calculated
type MediumID ¶
type MediumID uint64
MediumID is an id for media
const ( MediumBook MediumID = iota + 1 MediumComic MediumNet MediumFullGame MediumGame MediumLyric MediumNews MediumSentences )
These are the named constants for medium IDs
func (MediumID) AdjustedAmount ¶
AdjustedAmount gives the amount after having taken into account the medium
type Preferences ¶
type Preferences struct{}
Preferences holds user specific preferences like timezone and privacy
func (*Preferences) Scan ¶
func (p *Preferences) Scan(src interface{}) error
Scan implements the sql.Scanner interface
type Ranking ¶
type Ranking struct { ID uint64 `json:"id" db:"id"` ContestID uint64 `json:"contest_id" db:"contest_id" valid:"required"` UserID uint64 `json:"user_id" db:"user_id" valid:"required"` Language LanguageCode `json:"language_code" db:"language_code" valid:"required"` Amount float32 `json:"amount" db:"amount" valid:"required"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` // Optional fields UserDisplayName string `json:"user_display_name" db:"user_display_name"` }
Ranking contains the data about a user that has entered a contest
func (Ranking) GetView ¶
func (r Ranking) GetView() RankingView
GetView gets the external view representation of a Ranking
type RankingRegistration ¶
type RankingRegistration struct { Start time.Time `json:"start" db:"start" valid:"required"` End time.Time `json:"end" db:"end" valid:"required"` ContestID uint64 `json:"contest_id" db:"contest_id" valid:"required"` Languages LanguageCodes `json:"languages" db:"language_code" valid:"required"` }
RankingRegistration holds the current contest registration
type RankingView ¶
type RankingView struct { ContestID uint64 `json:"contest_id"` UserID uint64 `json:"user_id"` UserDisplayName string `json:"user_display_name"` Language LanguageCode `json:"language_code"` Amount float32 `json:"amount"` }
RankingView is a representation of a ranking for external usages
type Rankings ¶
type Rankings []Ranking
Rankings is a collection of Ranking
func (Rankings) GetView ¶
func (r Rankings) GetView() []RankingView
GetView gets the external view representation of a Rankings collection
type User ¶
type User struct { ID uint64 `json:"id" db:"id"` Email string `json:"email" db:"email"` DisplayName string `json:"display_name" db:"display_name" valid:"required"` Role Role `json:"role" db:"role"` Preferences *Preferences `json:"preferences" db:"preferences"` }
User holds everything related to a user's account data