Documentation ¶
Index ¶
- Constants
- func CountUsers(username string) int
- type Attribute
- type AttributesBundle
- type Bundle
- type BundleType
- type EpisodeBundle
- type SeriesBundle
- func (sb *SeriesBundle) FromBundle(bundleStore map[string]sql.NullString) error
- func (sb *SeriesBundle) Head() *EpisodeBundle
- func (sb *SeriesBundle) NumberOfEpisodes() int
- func (sb *SeriesBundle) Persist() error
- func (sb *SeriesBundle) PersistWith(tx *sql.Tx) error
- func (sb *SeriesBundle) SelectByName(seriesName string) error
- func (sb *SeriesBundle) Tail() []*EpisodeBundle
- func (sb *SeriesBundle) ToBundle() map[string]sql.NullString
- type Session
- type Torrent
- func (t *Torrent) Attributes() (*Attribute, error)
- func (t *Torrent) LoadTorrent() (*torrent.TorrentFile, error)
- func (t *Torrent) Populate(torrentFile *torrent.TorrentFile) error
- func (t *Torrent) SelectHash(hash string) error
- func (t *Torrent) SelectId(id int) error
- func (t *Torrent) SelectSummaryPage() ([]*Torrent, error)
- func (t *Torrent) SetAttributes(attributes *Attribute)
- func (t *Torrent) Write() error
- func (t *Torrent) WriteFile(secret, hash []byte) ([]byte, error)
- type User
- type UserModelError
Constants ¶
const ( USERNAME_TAKEN UserModelError = 1 << iota USERNAME_INVALID_CHAR = 1 << iota FAIL_GEN_SECRET = 1 << iota )
const (
SESSIONS_TABLE string = "sessions"
)
Variables ¶
This section is empty.
Functions ¶
func CountUsers ¶
Returns -1 if user count cannot be established. Returns 0 or 1 if user exists. Can return > 1 but schema would prevent it.
Types ¶
type Attribute ¶
type Attribute struct { TorrentId int // Name string ArtistName []string AlbumName string ReleaseYear time.Time MusicFormat string DiscNumber int Discs int AlbumDescription string ReleaseDescription string // contains filtered or unexported fields }
An attribute record stores meta-data which can be attached to a torrent.
func (*Attribute) SelectTorrent ¶
type AttributesBundle ¶
type AttributesBundle struct { ID int ParentID int Category BundleType Bundle hstore.Hstore Modified time.Time }
This is my bundle There are many like it, but this one is mine.
type BundleType ¶
type BundleType string
const ( BUNDLE_SERIES BundleType = "series" BUNDLE_EPISODE = "episode" )
type EpisodeBundle ¶
type EpisodeBundle struct { ID int `json:"episodeId"` TorrentID int `json:"torrentId"` Number int `json:"number"` Name string `json:"name"` Format string `json:"format"` Resolution string `json:"resolution"` }
func LatestEpisodes ¶
func LatestEpisodes() []*EpisodeBundle
TODO: Pagination Select the latest episodes, regardless of series.
func (*EpisodeBundle) FromBundle ¶
func (eb *EpisodeBundle) FromBundle(bundleStore map[string]sql.NullString) error
Implements Bundle interface and loads an EpisodeBundle object from a deserialized postgresql hstore field.
func (*EpisodeBundle) PersistWithSeries ¶
func (eb *EpisodeBundle) PersistWithSeries(series *SeriesBundle) error
func (*EpisodeBundle) ToBundle ¶
func (eb *EpisodeBundle) ToBundle() map[string]sql.NullString
type SeriesBundle ¶
type SeriesBundle struct { ID int `json:"bundleId"` TorrentID int `json:"torrentId"` Name string `json:"name"` Episodes []*EpisodeBundle `json:"episodes"` }
func LatestSeries ¶
func LatestSeries() []*SeriesBundle
Selects the latest series' of television.
This will select 100 series at a time which have a torrent or episode(s) associated with them.
func (*SeriesBundle) FromBundle ¶
func (sb *SeriesBundle) FromBundle(bundleStore map[string]sql.NullString) error
Implements Bundle interface and loads an SeriesBundle object from a deserialized postgresql hstore field.
func (*SeriesBundle) Head ¶
func (sb *SeriesBundle) Head() *EpisodeBundle
func (*SeriesBundle) NumberOfEpisodes ¶
func (sb *SeriesBundle) NumberOfEpisodes() int
func (*SeriesBundle) Persist ¶
func (sb *SeriesBundle) Persist() error
func (*SeriesBundle) PersistWith ¶
func (sb *SeriesBundle) PersistWith(tx *sql.Tx) error
TODO: Try update first.
func (*SeriesBundle) SelectByName ¶
func (sb *SeriesBundle) SelectByName(seriesName string) error
Attempts to populate series bundle by name. Otherwise this series bundle will be inserted.
func (*SeriesBundle) Tail ¶
func (sb *SeriesBundle) Tail() []*EpisodeBundle
func (*SeriesBundle) ToBundle ¶
func (sb *SeriesBundle) ToBundle() map[string]sql.NullString
type Torrent ¶
type Torrent struct { ID int `field:"torrent_id"` Name string `field:"name"` InfoHash string `field:"info_hash"` CreatedBy string `field:"created_by"` CreationDate int `field:"creation_date"` Encoding string `field:"encoding"` EncodedInfo []byte `field:"info_bencoded"` Seeding int Leeching int // contains filtered or unexported fields }
Define record structure. Tags aren't used anywhere . . .
Mostly use them as references, might use them for some sort of ORM in the future.
func (*Torrent) Attributes ¶
func (*Torrent) LoadTorrent ¶
func (t *Torrent) LoadTorrent() (*torrent.TorrentFile, error)
func (*Torrent) SelectHash ¶
Looks up a torrent based on its info hash, this is a 20-byte SHA which is encoded as a string [2-chars per byte.]
func (*Torrent) SelectSummaryPage ¶
Selects an excerpt of torrents. Only fetches an ID, InfoHash, and CreatedBy
func (*Torrent) SetAttributes ¶
type User ¶
type User struct { UserId int Username string IsAdmin bool Email string Secret []byte SecretHash []byte // contains filtered or unexported fields }
`User` model for `users`
func (*User) CheckHash ¶
Must be performed on an initialized user-struct. Returns an error if the user's password cannot be validated.
func (*User) SelectId ¶
Select user by ID number and populate the current `user` struct with the record data. Returns an error if there was a problem. fetching the user information from the database.
func (*User) SelectSecret ¶
Selects a user by their secret key. This is used by the tracker to authorize a user.
The secret is expected to be a UTF8 string representing a byte array using 2-characters per byte. (As per the standard encoding/hex package.)
func (*User) SelectUsername ¶
Select user by username and populate the current `user` struct with the record data. Returns an error if there was a problem. fetching the user information from the database.
type UserModelError ¶
type UserModelError int
Error-codes returned from some methods that could be presented to the UI.
func NewUser ¶
func NewUser(username, password string) (UserModelError, error)
Creates a new user record in the database. The first return parameter is an error-code that represents a non-fatal problem that could be presented to the user.
The second return parameter is a fatal error passed up from the database layer.