Documentation
¶
Index ¶
- Constants
- Variables
- func EnsureUserLoggedIn(next endpoint.Endpoint) endpoint.Endpoint
- func MakeAddMainPlaylistEntryEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeAddPlaylistEntryEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeAddToWhitelistEndpoint(s ConfigService) endpoint.Endpoint
- func MakeCreatePlaylistEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeDeleteEntryEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeDeletePlaylistEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeDeleteVideoEndpoint(s VideoService) endpoint.Endpoint
- func MakeGetMainPlaylistEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeGetPlaylistEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeGetScrapeEndpoint(s ScrapingService) endpoint.Endpoint
- func MakeGetVideoEndpoint(s VideoService) endpoint.Endpoint
- func MakeGetWhitelistEndpoint(s ConfigService) endpoint.Endpoint
- func MakeHTTPHandler(ss ScrapingService, vs VideoService, ps PlaylistService, es EventService, ...) http.Handler
- func MakeListDirsEndpoint(s ScrapingService) endpoint.Endpoint
- func MakeListMainPlaylistEntriesEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeListPlaylistEntriesEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeListPlaylistsEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeListScrapesEndpoint(s ScrapingService) endpoint.Endpoint
- func MakeListVideosEndpoint(s VideoService) endpoint.Endpoint
- func MakePlaceEntryBeforeEndpint(s PlaylistService) endpoint.Endpoint
- func MakeRemoveFromWhitelistEndpoint(s ConfigService) endpoint.Endpoint
- func MakeStartEndpoint(s ScrapingService) endpoint.Endpoint
- func MakeUpdateEntryEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeUpdatePlaylistEndpoint(s PlaylistService) endpoint.Endpoint
- func MakeUpdateVideoEndpoint(s VideoService) endpoint.Endpoint
- type ConfigEndpoints
- type ConfigService
- type EventEndpoints
- type EventService
- type HTTPError
- type Pagination
- type PlaylistEndpoints
- type PlaylistService
- type RootDirSorter
- type ScrapingEndpoints
- type ScrapingService
- type Search
- type SessionEndpoints
- type SessionInfo
- type SessionService
- type VideoEndpoints
- type VideoService
Constants ¶
const ( // ErrCodeUnknown is the error code for unknown errors ErrCodeUnknown = "UNKNOWN_ERROR" // ErrCodeIllegalPath is the error that is returned when the client did not send a valid path parameter ErrCodeIllegalPath = "ILLEGAL_PATH" // ErrCodeDirNotFound is returned when the client requests an operation that has been started with a nonexisting // directory ErrCodeDirNotFound = "DIR_NOT_FOUND" // ErrCodeScrapeRunning is returned when a new scrape is requested that will run in a directory that is already // inside the scraping queue ErrCodeScrapeRunning = "SCRAPE_ALREADY_QUEUED" // ErrCodeRepoError is returned when the request to a repo fails with an error ErrCodeRepoError = "STORAGE_QUERY_FAILED" // ErrCodeRequiredFieldMissing is returned when at least one required field has not been populated on an incoming // request ErrCodeRequiredFieldMissing = "REQUIRED_FIELD_MISSING" // ErrCodeIllegalJSON is returned when the request did not contain a valid JSON body ErrCodeIllegalJSON = "ILLEGAL_JSON_REQUEST" // ErrCodeIllegalValue is returned when any field in the transferred data does not validate for some reason ErrCodeIllegalValue = "ILLEGAL_VALUE" // ErrCodePlaylistNotFound is returned when an operation works on a playlist thas does not exist ErrCodePlaylistNotFound = "PLAYLIST_NOT_FOUND" // ErrCodePlaylistEntryNotFound is returned when an operation should be executed on a non-existing playlist entry ErrCodePlaylistEntryNotFound = "PLAYLIST_ENTRY_NOT_FOUND" // ErrCodePlaylistLockedForNewEntries is returned when a playlist is locked for adding new playlist entries ErrCodePlaylistLockedForNewEntries = "PLAYLIST_LOCKED_FOR_ADDING" // ErrCodeTooManyWishes is returned when an IP address requests more than the allowed number of videos ErrCodeTooManyWishes = "TOO_MANY_WISHES" // ErrCodeDuplicateWishesNotAllowed is returned when there are no duplicate wishes allowed for the main playlist and // a guest tries to add a video that has already been wished for ErrCodeDuplicateWishesNotAllowed = "NO_DUPLICATE_WISHES" // ErrCodeEventNotFound is returned when an operation works on an event that does not exist ErrCodeEventNotFound = "EVENT_NOT_FOUND" // ErrCodeInvalidUint is returned when an ID is required inside a request, but is not provided or in a wrong format ErrCodeInvalidUint = "INVALID_UINT" // ErrCodeNoCurrentEvent is returned when something depending on a currently active event is requested, but no // event is currently active ErrCodeNoCurrentEvent = "NO_EVENT_SELECTED" // ErrCodeVideoNotFound is returned when a referenced video does not exist ErrCodeVideoNotFound = "VIDEO_NOT_FOUND" // ErrCodeLoginFailed is returned when the user fails to login for some reason ErrCodeLoginFailed = "LOGIN_FAILED" // ErrCodeNotLoggedIn is returned when the user tried to access an API that needs a logged-in user, but the user // has no authenticated session ErrCodeNotLoggedIn = "NOT_LOGGED_IN" )
Variables ¶
var ( // ErrIllegalIP is the error returned when the provided string is no valid IP address ErrIllegalIP = MakeError(http.StatusBadRequest, "ILLEGAL_IP_ADDRESS", "Illegal IP address provided") )
var ( // ErrNoCurrentEvent is the default error returned when something requests an operation that depends on an event // being selected as current event, while no event has been selected ErrNoCurrentEvent = MakeError( http.StatusExpectationFailed, ErrCodeNoCurrentEvent, "No active event selected", ) )
Functions ¶
func EnsureUserLoggedIn ¶
EnsureUserLoggedIn is a middleware that checks if there is a valid user session for the current call
func MakeAddMainPlaylistEntryEndpoint ¶
func MakeAddMainPlaylistEntryEndpoint(s PlaylistService) endpoint.Endpoint
MakeAddMainPlaylistEntryEndpoint returns an endpoint calling the AddMainEntry method on the provided PlaylistService
func MakeAddPlaylistEntryEndpoint ¶
func MakeAddPlaylistEntryEndpoint(s PlaylistService) endpoint.Endpoint
MakeAddPlaylistEntryEndpoint returns an endpoint calling the AddEntry method on the provided PlaylistService
func MakeAddToWhitelistEndpoint ¶
func MakeAddToWhitelistEndpoint(s ConfigService) endpoint.Endpoint
MakeAddToWhitelistEndpoint returns and endpoint calling the AddToWhitelist method of the ConfigService
func MakeCreatePlaylistEndpoint ¶
func MakeCreatePlaylistEndpoint(s PlaylistService) endpoint.Endpoint
MakeCreatePlaylistEndpoint returns an endpoint calling the Create method on the provided PlaylistService
func MakeDeleteEntryEndpoint ¶
func MakeDeleteEntryEndpoint(s PlaylistService) endpoint.Endpoint
MakeDeleteEntryEndpoint returns an endpoint calling the DeleteEntry method on the provided PlaylistService
func MakeDeletePlaylistEndpoint ¶
func MakeDeletePlaylistEndpoint(s PlaylistService) endpoint.Endpoint
MakeDeletePlaylistEndpoint returns an endpoint calling the Delete method on the provided PlaylistService
func MakeDeleteVideoEndpoint ¶
func MakeDeleteVideoEndpoint(s VideoService) endpoint.Endpoint
MakeDeleteVideoEndpoint returns an endpoint calling the List method on the provided VideoService
func MakeGetMainPlaylistEndpoint ¶
func MakeGetMainPlaylistEndpoint(s PlaylistService) endpoint.Endpoint
MakeGetMainPlaylistEndpoint returns an endpoint calling the GetMain method on the provided PlaylistService
func MakeGetPlaylistEndpoint ¶
func MakeGetPlaylistEndpoint(s PlaylistService) endpoint.Endpoint
MakeGetPlaylistEndpoint returns an endpoint calling the Get method on the provided PlaylistService
func MakeGetScrapeEndpoint ¶
func MakeGetScrapeEndpoint(s ScrapingService) endpoint.Endpoint
MakeGetScrapeEndpoint returns an endpoint calling the GetScrape method on the provided ScrapingService
func MakeGetVideoEndpoint ¶
func MakeGetVideoEndpoint(s VideoService) endpoint.Endpoint
MakeGetVideoEndpoint returns an endpoint calling the List method on the provided VideoService
func MakeGetWhitelistEndpoint ¶
func MakeGetWhitelistEndpoint(s ConfigService) endpoint.Endpoint
MakeGetWhitelistEndpoint returns and endpoint calling the GetWhitelist method of the ConfigService
func MakeHTTPHandler ¶
func MakeHTTPHandler( ss ScrapingService, vs VideoService, ps PlaylistService, es EventService, sServ SessionService, cs ConfigService, logger *logrus.Entry, ) http.Handler
MakeHTTPHandler creates the main HTTP handler for the Kyabia service
func MakeListDirsEndpoint ¶
func MakeListDirsEndpoint(s ScrapingService) endpoint.Endpoint
MakeListDirsEndpoint returns an endpoint calling the ListDirs method on the provided ScrapingService
func MakeListMainPlaylistEntriesEndpoint ¶
func MakeListMainPlaylistEntriesEndpoint(s PlaylistService) endpoint.Endpoint
MakeListMainPlaylistEntriesEndpoint returns an endpoint calling the ListMainEntries method on the provided PlaylistService
func MakeListPlaylistEntriesEndpoint ¶
func MakeListPlaylistEntriesEndpoint(s PlaylistService) endpoint.Endpoint
MakeListPlaylistEntriesEndpoint returns an endpoint calling the ListEntries method on the provided PlaylistService
func MakeListPlaylistsEndpoint ¶
func MakeListPlaylistsEndpoint(s PlaylistService) endpoint.Endpoint
MakeListPlaylistsEndpoint returns an endpoint calling the Create method on the provided PlaylistService
func MakeListScrapesEndpoint ¶
func MakeListScrapesEndpoint(s ScrapingService) endpoint.Endpoint
MakeListScrapesEndpoint returns an endpoint calling the ListScrapes method on the provided ScrapingService
func MakeListVideosEndpoint ¶
func MakeListVideosEndpoint(s VideoService) endpoint.Endpoint
MakeListVideosEndpoint returns an endpoint calling the List method on the provided VideoService
func MakePlaceEntryBeforeEndpint ¶
func MakePlaceEntryBeforeEndpint(s PlaylistService) endpoint.Endpoint
MakePlaceEntryBeforeEndpint returns an endpoint calling the PlaceEntryBefore method on the provided PlaylistService
func MakeRemoveFromWhitelistEndpoint ¶
func MakeRemoveFromWhitelistEndpoint(s ConfigService) endpoint.Endpoint
MakeRemoveFromWhitelistEndpoint returns and endpoint calling the RemoveFromWhitelist method of the ConfigService
func MakeStartEndpoint ¶
func MakeStartEndpoint(s ScrapingService) endpoint.Endpoint
MakeStartEndpoint returns an endpoint calling the Start method on the provided ScrapingService
func MakeUpdateEntryEndpoint ¶
func MakeUpdateEntryEndpoint(s PlaylistService) endpoint.Endpoint
MakeUpdateEntryEndpoint returns an endpoint calling the UpdateEntry method on the provided PlaylistService
func MakeUpdatePlaylistEndpoint ¶
func MakeUpdatePlaylistEndpoint(s PlaylistService) endpoint.Endpoint
MakeUpdatePlaylistEndpoint returns an endpoint calling the Update method on the provided PlaylistService
func MakeUpdateVideoEndpoint ¶
func MakeUpdateVideoEndpoint(s VideoService) endpoint.Endpoint
MakeUpdateVideoEndpoint returns an endpoint calling the List method on the provided VideoService
Types ¶
type ConfigEndpoints ¶
type ConfigEndpoints struct {
GetWhitelist endpoint.Endpoint
AddToWhitelist endpoint.Endpoint
RemoveFromWhitelist endpoint.Endpoint
}
ConfigEndpoints is a collection of endpoints for changing the system's configuration
func MakeConfigEndpoints ¶
func MakeConfigEndpoints(s ConfigService) ConfigEndpoints
MakeConfigEndpoints creates the endpoints needed to use the configuration service
type ConfigService ¶
type ConfigService interface {
// WhitelistedIPs returns the list of IP addresses that have been whitelisted for removing the restrictions guests
// have when using Kyabia like limiting the total amount of wishes on the wishlist
WhitelistedIPs(ctx context.Context) []string
// AddToWhitelist adds an IP address to the list hosts without guest restrictions
AddToWhitelist(ctx context.Context, ipAddr string) error
// RemoveFromWhitelist removes an IP address from the list of hosts that have no guest restrictions
RemoveFromWhitelist(ctx context.Context, ipAddr string) error
// IsWhitelisted checks if the given IP address has been whitelisted
IsWhitelisted(ipAddr string) bool
// Load loads the application config from its default file location
Load(ctx context.Context) error
// LoadFromFile loads the configuration from the given JSON file and returns it
LoadFromFile(ctx context.Context, filename string) error
// Write writes the current application configuration to the default file name
Write(ctx context.Context) error
// WriteToFile writes the current application configuration to a JSON file
WriteToFile(ctx context.Context, filename string) error
// GetConfig retuns the current application configuration
GetConfig(ctx context.Context) models.AppConfig
}
ConfigService gives the authenticated user access to parts of the application's configuration
func NewConfigService ¶
func NewConfigService(configFilename string) ConfigService
NewConfigService creates a new configuration service instance with the given default file name
type EventEndpoints ¶
type EventEndpoints struct {
List endpoint.Endpoint
Get endpoint.Endpoint
Create endpoint.Endpoint
Update endpoint.Endpoint
Delete endpoint.Endpoint
SetCurrentEvent endpoint.Endpoint
CurrentEvent endpoint.Endpoint
DefaultPlaylistID endpoint.Endpoint
}
EventEndpoints is a collection of endpoints for working with the event service
func MakeEventEndpoints ¶
func MakeEventEndpoints(s EventService) EventEndpoints
MakeEventEndpoints builds the endpoints needed to communicate with the Event Service
type EventService ¶
type EventService interface {
List(ctx context.Context, search *Search) ([]models.Event, uint, error)
Get(ctx context.Context, id uint) (*models.Event, error)
Create(ctx context.Context, event *models.Event) (*models.Event, error)
Update(ctx context.Context, event *models.Event) error
Delete(ctx context.Context, id uint) error
SetCurrentEvent(ctx context.Context, id uint) error
CurrentEvent(ctx context.Context) (*models.Event, error)
DefaultPlaylistID(ctx context.Context) uint
}
EventService provides service functions for working with events
func NewEventService ¶
func NewEventService(repo repos.EventRepo, playlists repos.PlaylistRepo, logger *logrus.Entry) EventService
NewEventService creates a new event service instance
type HTTPError ¶
type HTTPError struct {
// contains filtered or unexported fields
}
HTTPError is an error that contains information about the error message to return to the client
func MakeErrorWithData ¶
MakeErrorWithData creates a new HTTPError with the given contents and an additional data element
func (*HTTPError) Data ¶
func (e *HTTPError) Data() interface{}
Data returns additional data about the error
type Pagination ¶
type Pagination struct {
// Position in the resultset to start the returned result at
Offset uint
// Number of items to return
Limit uint
}
Pagination describes a request that uses paging data to retrieve only a subset of the full result
type PlaylistEndpoints ¶
type PlaylistEndpoints struct {
Create endpoint.Endpoint
Get endpoint.Endpoint
Update endpoint.Endpoint
Delete endpoint.Endpoint
List endpoint.Endpoint
ListEntries endpoint.Endpoint
AddEntry endpoint.Endpoint
UpdateEntry endpoint.Endpoint
DeleteEntry endpoint.Endpoint
PlaceEntryBefore endpoint.Endpoint
GetMain endpoint.Endpoint
ListMainEntries endpoint.Endpoint
AddMainEntry endpoint.Endpoint
}
PlaylistEndpoints is a collection of endpoints for working with the playlist service
func MakePlaylistEndpoints ¶
func MakePlaylistEndpoints(s PlaylistService) PlaylistEndpoints
MakePlaylistEndpoints creates the endpoints needed for using the playlist service
type PlaylistService ¶
type PlaylistService interface {
List(ctx context.Context, search *Search) ([]models.Playlist, uint, error)
Get(ctx context.Context, id uint) (*models.Playlist, error)
Create(ctx context.Context, playlist *models.Playlist) (*models.Playlist, error)
Update(ctx context.Context, playlist *models.Playlist) error
Delete(ctx context.Context, id uint) error
ListEntries(ctx context.Context, id uint, offset uint, limit uint) ([]models.PlaylistVideoEntry, uint, error)
AddEntry(ctx context.Context, id uint, entry *models.PlaylistEntry) error
UpdateEntry(ctx context.Context, entry models.PlaylistEntry) error
DeleteEntry(ctx context.Context, id uint) error
PlaceEntryBefore(ctx context.Context, entryID uint, otherEntryID uint) error
GetMain(ctx context.Context) (*models.Playlist, error)
ListMainEntries(ctx context.Context, offset uint, limit uint) ([]models.PlaylistVideoEntry, uint, error)
AddMainEntry(ctx context.Context, entry *models.PlaylistEntry) error
}
PlaylistService provides service functions for working with playlists
func NewPlaylistService ¶
func NewPlaylistService(pRepo repos.PlaylistRepo, vRepo repos.VideoRepo, events EventService, cs ConfigService, logger *logrus.Entry) PlaylistService
NewPlaylistService creates a new PlaylistService instance
type RootDirSorter ¶
RootDirSorter is a helper for sorting a scrape slice since Go decided to be complicated here
func (RootDirSorter) Len ¶
func (n RootDirSorter) Len() int
Len is the number of elements in the collection.
func (RootDirSorter) Less ¶
func (n RootDirSorter) Less(i, j int) bool
Less reports whether the element with index i should sort before the element with index j.
func (RootDirSorter) Swap ¶
func (n RootDirSorter) Swap(i, j int)
Swap swaps the elements with indexes i and j.
type ScrapingEndpoints ¶
type ScrapingEndpoints struct {
ListDirs endpoint.Endpoint
ListScrapes endpoint.Endpoint
GetScrape endpoint.Endpoint
Start endpoint.Endpoint
}
ScrapingEndpoints is a collection of endpoints to the scraping service
func MakeScrapingEndpoints ¶
func MakeScrapingEndpoints(s ScrapingService) ScrapingEndpoints
MakeScrapingEndpoints creates the endpoints needed to use the scraping service
type ScrapingService ¶
type ScrapingService interface {
ListDirs(ctx context.Context, parentDir string) ([]string, error)
ListScrapes(ctx context.Context) ([]scraper.Scrape, error)
GetScrape(ctx context.Context, rootDir string) *scraper.Scrape
Start(ctx context.Context, rootDir string) error
}
ScrapingService is a service that provides functionality scraping videos from a directory into the database of Kyabia
func NewScrapingService ¶
func NewScrapingService(scr *scraper.Scraper, logger *logrus.Entry) ScrapingService
NewScrapingService creates a new scraping service instance using the provided scraper and logger
type Search ¶
type Search struct {
Pagination
// The string to search for
Search string
}
Search describes a typical search request with a search term and pagination information
type SessionEndpoints ¶
type SessionEndpoints struct {
Login endpoint.Endpoint
Logout endpoint.Endpoint
WhoAmI endpoint.Endpoint
}
SessionEndpoints is a collection of endpoints for working with the session service
func MakeSessionEndpoints ¶
func MakeSessionEndpoints(s SessionService) SessionEndpoints
MakeSessionEndpoints builds the endpoints needed to communicate with the Session Service
type SessionInfo ¶
type SessionInfo struct {
SessionID string `json:"sessionId"`
UserName string `json:"userName"`
UserFullName string `json:"userFullName"`
}
SessionInfo is a session information object that is returned upon login. It contains both, the session ID and information about the user that is logged in
type SessionService ¶
type SessionService interface {
// Login tries to log-in the user with the given credentials and returns the info about the created session if login
// was successful
Login(ctx context.Context, user string, password string) (*SessionInfo, error)
// Logout logs out a currently active session
Logout(ctx context.Context, sessionID string) error
// WhoAmI returns information about the current session
WhoAmI(ctx context.Context, sessionID string) (*SessionInfo, error)
// GetContents returns the session and user data associated with the given session ID
// This service function will be used internally and does not have an endpoint
GetContents(ctx context.Context, sessionID string, extendExpiry bool) (*models.Session, *models.User, error)
}
SessionService provides functions for interacting with a user's session
func NewSessionService ¶
func NewSessionService(sr repos.SessionRepo, ur repos.UserRepo, logger *logrus.Entry) SessionService
NewSessionService creates a new session service instance with the provided repositories
type VideoEndpoints ¶
type VideoEndpoints struct {
List endpoint.Endpoint
Get endpoint.Endpoint
Update endpoint.Endpoint
Delete endpoint.Endpoint
}
VideoEndpoints is a collection of endpoints to the video service
func MakeVideoEndpoints ¶
func MakeVideoEndpoints(s VideoService) VideoEndpoints
MakeVideoEndpoints creates the endpoints needed for using the video service
type VideoService ¶
type VideoService interface {
// List searches for videos matching the provided search and returns a list of paged results
List(ctx context.Context, search *Search) ([]models.Video, uint, error)
// Get returns the video with the given ID (SHA-512 hash)
Get(ctx context.Context, id string) (*models.Video, error)
// Update updates the given video in the database with the video data provided
Update(ctx context.Context, video *models.Video) error
// Delete removes the video with the given ID (SHA-512 hash) from the database
Delete(ctx context.Context, id string) error
}
VideoService provides functionality for listing scraped videos
func NewVideoService ¶
func NewVideoService(vRepo repos.VideoRepo, logger *logrus.Entry) VideoService
NewVideoService creates a new videoService instance to use for creating endpoints
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ctxhelper provides helper functions for working with the context
|
Package ctxhelper provides helper functions for working with the context |
|
Package migrate handles SQL database migration for the internal Kyabia database
|
Package migrate handles SQL database migration for the internal Kyabia database |
|
Package models contains the models used in the Kyabia application
|
Package models contains the models used in the Kyabia application |
|
Package repos contains the repository interfaces needed in Kyabia It exists to prevent circular dependencies between kyabia and the repo implementations
|
Package repos contains the repository interfaces needed in Kyabia It exists to prevent circular dependencies between kyabia and the repo implementations |
|
event/sqlite
Package sqlite provides an event repository that stores its data inside a SQLite database
|
Package sqlite provides an event repository that stores its data inside a SQLite database |
|
playlist/sqlite
Package sqlite contains a repository for playlists that stores its data inside a SQLite database
|
Package sqlite contains a repository for playlists that stores its data inside a SQLite database |
|
session/inmem
Package inmem provides a session repository that holds the session data in-memory
|
Package inmem provides a session repository that holds the session data in-memory |
|
user/inmem
Package inmem provides a user repository that works from memory.
|
Package inmem provides a user repository that works from memory. |
|
video/sqlite
Package sqlite provides a video repository that uses SQLite for storing video information
|
Package sqlite provides a video repository that uses SQLite for storing video information |
|
Package scraper provides video file scraping functionality
|
Package scraper provides video file scraping functionality |