Documentation ¶
Index ¶
- Constants
- func ErrorHandler(w http.ResponseWriter, error string, code int)
- func GenerateKey() (string, error)
- func InSlice(slice []string, target string) bool
- type App
- type AuthClient
- func (ac *AuthClient) Authenticate(w http.ResponseWriter, r *http.Request, email, password string) (*models.User, error)
- func (ac *AuthClient) ClearUser(w http.ResponseWriter, r *http.Request) error
- func (ac *AuthClient) CurUser(r *http.Request) (*models.User, error)
- func (ac AuthClient) HttprouterMiddleware(h httprouter.Handle) httprouter.Handle
- func (ac AuthClient) Middleware(h http.Handler) http.Handler
- func (ac AuthClient) Redirect(w http.ResponseWriter, r *http.Request)
- type ContextKey
- type MongoClient
- func (mc *MongoClient) CreateUser(user *models.User) error
- func (mc *MongoClient) FindMedia(path string) (*models.Media, error)
- func (mc *MongoClient) GetAllMedia(email string) (*models.MediaList, error)
- func (mc *MongoClient) GetSession() *mgo.Session
- func (mc *MongoClient) GetUserFromDB(email string, hash []byte) (*models.User, error)
- func (mc *MongoClient) InsertMedia(media *models.Media) error
- func (mc *MongoClient) RemoveMedia(mediaID string) error
- func (mc *MongoClient) UpdateMedia(media *models.Media) error
- func (mc *MongoClient) UpdateSubtitle(name, path string) error
- type RedisClient
- func (rc *RedisClient) ClearAuthCache(key []byte) error
- func (rc *RedisClient) GetAuthCache(key []byte) ([]byte, error)
- func (rc *RedisClient) GetEncodedPath(media *models.Media, ipAddr string) (string, error)
- func (rc *RedisClient) GetMedia(encodedPath, ipAddr string) (*models.Media, error)
- func (rc *RedisClient) SetAuthCache(userID string, data []byte) ([]byte, error)
- type StaticFileSystem
Constants ¶
const ( DATA = iota SUBTITLE )
Variables ¶
This section is empty.
Functions ¶
func ErrorHandler ¶
func ErrorHandler(w http.ResponseWriter, error string, code int)
ErrorHandler returns HTTP response with json error message
Types ¶
type App ¶
type App struct { *httprouter.Router // contains filtered or unexported fields }
App is GoVideo Web Application TODO: add securecookie
type AuthClient ¶
type AuthClient struct { *sessions.CookieStore // cookie session to store user info *MongoClient // db client to store user info *RedisClient // contains filtered or unexported fields }
AuthClient provides authentication
func NewAuthClient ¶
func NewAuthClient(store *sessions.CookieStore, db *MongoClient, cache *RedisClient) (*AuthClient, error)
NewAuthClient creates new AuthClient with random key
func (*AuthClient) Authenticate ¶
func (ac *AuthClient) Authenticate(w http.ResponseWriter, r *http.Request, email, password string) (*models.User, error)
Authenticate authenticates user with provided credentials To be called by login handler
func (*AuthClient) ClearUser ¶
func (ac *AuthClient) ClearUser(w http.ResponseWriter, r *http.Request) error
ClearUser removes current user session
func (AuthClient) HttprouterMiddleware ¶
func (ac AuthClient) HttprouterMiddleware(h httprouter.Handle) httprouter.Handle
HttprouterMiddleware -
func (AuthClient) Middleware ¶
func (ac AuthClient) Middleware(h http.Handler) http.Handler
Middleware for authentication
func (AuthClient) Redirect ¶
func (ac AuthClient) Redirect(w http.ResponseWriter, r *http.Request)
Redirect redirects to authenticate uri
type MongoClient ¶
type MongoClient struct {
// contains filtered or unexported fields
}
MongoClient holds master session and other db-related info
func NewMongoClient ¶
func NewMongoClient(uri, dbName string) (*MongoClient, error)
NewMongoClient establishes connection to MongoDB database and returns new MongoClient object
func (*MongoClient) CreateUser ¶
func (mc *MongoClient) CreateUser(user *models.User) error
CreateUser -
func (*MongoClient) FindMedia ¶
func (mc *MongoClient) FindMedia(path string) (*models.Media, error)
FindMedia - recycle media after use
func (*MongoClient) GetAllMedia ¶
func (mc *MongoClient) GetAllMedia(email string) (*models.MediaList, error)
GetAllMedia -
func (*MongoClient) GetSession ¶
func (mc *MongoClient) GetSession() *mgo.Session
GetSession returns mgo.Session copied from MongoClient's master session Be sure to close the session after done
func (*MongoClient) GetUserFromDB ¶
GetUserFromDB -
func (*MongoClient) InsertMedia ¶
func (mc *MongoClient) InsertMedia(media *models.Media) error
InsertMedia -
func (*MongoClient) RemoveMedia ¶
func (mc *MongoClient) RemoveMedia(mediaID string) error
RemoveMedia -
func (*MongoClient) UpdateMedia ¶
func (mc *MongoClient) UpdateMedia(media *models.Media) error
UpdateMedia -
func (*MongoClient) UpdateSubtitle ¶
func (mc *MongoClient) UpdateSubtitle(name, path string) error
UpdateSubtitle -
type RedisClient ¶
RedisClient -
func NewRedisClient ¶
func NewRedisClient(config *models.Config) (*RedisClient, error)
NewRedisClient -
func (*RedisClient) ClearAuthCache ¶
func (rc *RedisClient) ClearAuthCache(key []byte) error
ClearAuthCache clears user data from redis cache
func (*RedisClient) GetAuthCache ¶
func (rc *RedisClient) GetAuthCache(key []byte) ([]byte, error)
GetAuthCache gets user data from redis cache
func (*RedisClient) GetEncodedPath ¶
GetEncodedPath returns encoded path from real file path
func (*RedisClient) GetMedia ¶
func (rc *RedisClient) GetMedia(encodedPath, ipAddr string) (*models.Media, error)
GetMedia returns Media struct from encodedPath make sure to release Media after use
func (*RedisClient) SetAuthCache ¶
func (rc *RedisClient) SetAuthCache(userID string, data []byte) ([]byte, error)
SetAuthCache sets user data in redis cache
type StaticFileSystem ¶
type StaticFileSystem struct {
// contains filtered or unexported fields
}
StaticFileSystem that disables directory listing https://groups.google.com/forum/#!topic/golang-nuts/bStLPdIVM6w