app

package
v0.0.0-...-074fcce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Config   *Config
	Database *db.Database
}

func New

func New() (app *App, err error)

func (*App) Close

func (a *App) Close() error

func (*App) ExtractToken

func (a *App) ExtractToken(tokenString string) *model.User

func (*App) NewContext

func (a *App) NewContext() *Context

func (*App) ValidateBearerToken

func (a *App) ValidateBearerToken(token string) (user *model.User, failureReason string, err error)

type Config

type Config struct {
	// A secret string used for session cookies, passwords, etc.
	SecretKey []byte
	JwtKey    []byte
}

func InitConfig

func InitConfig() (*Config, error)

type Context

type Context struct {
	Logger        logrus.FieldLogger
	RemoteAddress string
	Database      *db.Database
	UserPlayhead  *model.UserPlayhead
	User          *model.User
}

func (*Context) AuthorizationError

func (ctx *Context) AuthorizationError() *UserPlayheadError

func (*Context) CreatePlayhead

func (ctx *Context) CreatePlayhead(playhead *model.UserPlayhead) error

func (*Context) DeletePlayheadBySeriesUUID

func (ctx *Context) DeletePlayheadBySeriesUUID(seriesUUID string) error

func (*Context) DeletePlayheadsForUser

func (ctx *Context) DeletePlayheadsForUser(userUUID string) error

func (*Context) GetPlayhead

func (ctx *Context) GetPlayhead(seriesUUID string) (*model.UserPlayhead, error)

Get a single playhead

func (*Context) GetPlayheadBySeriesId

func (ctx *Context) GetPlayheadBySeriesId(seriesUUID string) (*model.UserPlayhead, error)

func (*Context) GetPlayheads

func (ctx *Context) GetPlayheads() ([]*model.UserPlayhead, error)

func (*Context) UpdatePlayhead

func (ctx *Context) UpdatePlayhead(playhead *model.UserPlayhead) error

func (*Context) WithLogger

func (ctx *Context) WithLogger(logger logrus.FieldLogger) *Context

func (*Context) WithRemoteAddress

func (ctx *Context) WithRemoteAddress(address string) *Context

func (*Context) WithUser

func (ctx *Context) WithUser(user *model.User) *Context

type CustomClaims

type CustomClaims struct {
	jwt.Claims
	// contains filtered or unexported fields
}
func (ctx *Context) WithBearerToken(token string) (*Context, error) {
	user, failureReason, err := ctx.App.ValidateBearerToken(token)
	if err != nil {
		return nil, err
	} else if failureReason != "" {
		ctx.Logger.WithField("reason", failureReason).Info("bearer token validation failure")
		return nil, nil
	}

	return ctx.WithUser(user), nil
}

type UserPlayheadError

type UserPlayheadError struct {
	Message    string `json:"message"`
	StatusCode int    `json:"-"`
}

func (*UserPlayheadError) Error

func (e *UserPlayheadError) Error() string

type ValidationError

type ValidationError struct {
	Message string `json:"message"`
}

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL