Documentation
¶
Overview ¶
Package config contains types and constants related to server configuration.
Index ¶
Constants ¶
const ( DatastoreKind = "Config" DatastoreKeyName = "active" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Users contains information about users who can access the server.
Users []User `yaml:"users"`
// SongBucket contains the name of the Google Cloud Storage bucket holding song files.
SongBucket string `yaml:"songBucket,omitempty"`
// CoverBucket contains the name of the Google Cloud Storage bucket holding album cover images.
CoverBucket string `yaml:"coverBucket,omitempty"`
// SongDir contains the directory under which song files are stored.
// This is used for testing. Exactly one of SongBucket and SongDir must be set.
SongDir string `yaml:"songDir,omitempty"`
// CoverDir contains the directory under which album cover images are stored.
// This is used for testing. Exactly one of CoverBucket and CoverDir must be set.
CoverDir string `yaml:"coverDir,omitempty"`
// Presets contains default search presets.
Presets []SearchPreset `yaml:"presets"`
// Minify describes whether the server should minify JavaScript, HTML, and CSS code
// and bundle all JavaScript code into a single file. Defaults to true if unset.
Minify *bool `yaml:"minify"`
// MaxGuestSongRequestsPerHour contains the maximum rate at which each guest
// user can send requests to the /song endpoint. Unlimited if 0 or negative.
MaxGuestSongRequestsPerHour int `yaml:"maxGuestSongRequestsPerHour,omitempty"`
}
Config holds the App Engine server's configuration.
func Load ¶
Load attempts to load the server's config from various locations. ctx must be an App Engine context.
func (*Config) GetUser ¶
GetUser attempts to find the user from cfg.Users that sent req. This method does not identify cron requests; use GetUserType for that. The returned User object is a shallow copy of the entry from cfg with its Password field cleared. If the request was unauthenticated or the user is not listed in cfg.Users, nil is returned. A username or email address that can be used in logging is returned if possible, even if the the request is not from a known user.
func (*Config) GetUserType ¶
GetUserType returns a UserType describing the user who sent req. If the request was unauthenticated or the user is not listed in cfg.Users, 0 is returned. A username or email address that can be used in logging is returned if possible, even if the the request is not from a known user.
type SavedConfig ¶
type SavedConfig struct {
Data string `datastore:"data,noindex"`
}
SavedConfig is used to store a YAML-marshaled Config in Datastore.
type SearchPreset ¶
type SearchPreset struct {
// Name contains a human-readable name describing the preset.
Name string `json:"name" yaml:"name"`
// Artist contains an artist name to search for.
Artist string `json:"artist" yaml:"artist"`
// Keywords contains a space-separated list of Song.Keywords values to require.
Keywords string `json:"keywords" yaml:"keywords"`
// Tags contains a space-separated tag expression, e.g. "guitar -banjo".
Tags string `json:"tags" yaml:"tags"`
// MinRating contains a minimum rating as number of stars in [1, 5].
MinRating int `json:"minRating" yaml:"minRating"`
// Unrated specifies that only unrated songs should be returned.
Unrated bool `json:"unrated" yaml:"unrated"`
// FirstPlayed limits results to songs first played within the given interval:
// 0 - no restriction
// 1 - last day
// 2 - last week
// 3 - last month
// 4 - last three months
// 5 - last six months
// 6 - last year
// 7 - last three years
// 8 - last five years
FirstPlayed int `json:"firstPlayed" yaml:"firstPlayed"`
// LastPlayed limits results to songs last played before the given interval.
// See FirstPlayed for values.
LastPlayed int `json:"lastPlayed" yaml:"lastPlayed"`
// OrderByLastPlayed specifies that songs should be ordered by the last time
// they were played (in ascending order).
OrderByLastPlayed bool `json:"orderByLastPlayed" yaml:"orderByLastPlayed"`
// MaxPlays specifies the maximum number of times that each song has been played.
MaxPlays *int `json:"maxPlays,omitempty" yaml:"maxPlays"`
// FirstTrack specifies that only albums' first tracks should be returned.
FirstTrack bool `json:"firstTrack" yaml:"firstTrack"`
// Shuffle specifies that the returned songs should be shuffled.
Shuffle bool `json:"shuffle" yaml:"shuffle"`
// Play specifies that returned songs should be played automatically.
// The current playlist is replaced.
Play bool `json:"play" yaml:"play"`
}
SearchPreset specifies a search preset to display. Both YAML and JSON field names are defined: YAML is used for configuration but JSON is used when generating responses to the server's /presets endpoint.
type User ¶
type User struct {
// Email contains an email address for Google authentication, used for the web interface.
Email string `json:"email" yaml:"email"`
// Username contains a username for HTTP basic auth, used by the Android client and the nup command-line executable.
Username string `json:"username" yaml:"username"`
// Password contains a password for HTTP basic auth.
Password string `json:"password" yaml:"password"`
// Admin is true if this user should have elevated permissions.
// This should only be set for the HTTP basic auth account used by the nup command-line executable.
Admin bool `json:"admin" yaml:"admin"`
// Guest is true if this user should have reduced permissions.
// Guest users are not allowed to rate/tag songs or report plays.
Guest bool `json:"guest" yaml:"guest"`
// Presets contains custom search presets for this user.
// If empty, Config.Presets will be used instead.
Presets []SearchPreset `json:"presets" yaml:"presets"`
// ExcludedTags contains a list of tags used to filter songs.
ExcludedTags []string `json:"excludedTags" yaml:"excludedTags"`
}
User contains information about a user allowed to access the server. Both YAML and JSON field names are defined: YAML is used for configuration but JSON is used when generating responses to the server's /user endpoint.
type UserType ¶
type UserType uint32
UserType describes the level of access granted to a user. A given user will have a single type, but UserType values can be masked together to make it easier to check permissions. 0 represents a non-user.
const ( // NormalUser indicates a non-admin, non-guest user. NormalUser UserType = 1 << iota // AdminUser indicates a user with its Admin field set to true. AdminUser // GuestUser indicates a user with its Guest field set to true. GuestUser // CronUser indicates a request issued by App Engine cron jobs. CronUser )