pkg

package
v0.0.0-...-914aa4b Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JWT secrets
	JWTSecretENV     = "jwt_secret"
	RefreshSecretENV = "refresh_secret"
	UserENV          = "user_secret"

	// Cookie settings
	CookieDomain = "localhost"
	CookiePath   = "/"
	// Token cookie names
	AuthToken    = "token"
	RefreshToken = "session"
	UserToken    = "user"
	UserContext  = "user"
)
View Source
const (
	ErrInitilizing        = 1
	ErrClosingDatabase    = 2
	ErrShuttingDownServer = 3
	ErrStartingServer     = 4
)

OS Exit Codes

Variables

View Source
var (
	// System Errors
	ErrDatabase    = errors.New("Database error")
	ErrNilDatabase = errors.New("Database information must not be nil")
	ErrBadRequest  = errors.New("Bad request")
	// User Errors
	ErrInvalidTokenAndUser        = errors.New("User token does not match user ID provided")
	ErrInvalidRefreshAndUser      = errors.New("Refresh token does not match user ID provided")
	ErrCreatingTokens             = errors.New("Error creating authentication token")
	ErrValidatingPassword         = errors.New("Error validating password")
	ErrIncorrectPassword          = errors.New("Incorrect password")
	ErrUserNotFound               = errors.New("User not found")
	ErrInvalidPermissionsToUpdate = errors.New("Invalid permissions to update user")
	ErrUpdateUser                 = errors.New("Error updating user")
	ErrCreateUser                 = errors.New("Error creating user")
	ErrRetrievingAllUsers         = errors.New("Unable to retrieve all users")
	ErrWrongArgonVersion          = errors.New("Incompatible argon2 version")
	ErrInvalidHash                = errors.New("Invalid hash")
	ErrReauthenticate             = errors.New("Error re-authenticating")
	ErrLoggingOut                 = errors.New("Error logging user out")
	// User Validation Errors
	ErrUsernameInUse    = errors.New("Username already in use")
	ErrEmailInUse       = errors.New("Email already in use")
	ErrUsernameSymbols  = errors.New("Username cannot contain symbols")
	ErrInvalidEmail     = errors.New("Invalid email address")
	ErrPasswordTooShort = errors.New("Password must contain at least 8 characters")
	ErrPasswordTooLong  = errors.New("Password cannot exceed 100 characters")
	ErrUsernameTooShort = errors.New("Username must contain at least 3 characters")
	ErrUsernameTooLong  = errors.New("Username cannot exceed 20 characters")
	ErrPasswordSymbol   = errors.New("Password must contain at least one symbol")
	ErrPasswordNum      = errors.New("Password must contain at least one number")
	ErrPasswordCapital  = errors.New("Password must contain at least one capital character")
)

Application Errors

Functions

This section is empty.

Types

type API

type API struct {
	Options Options
}

func New

func New(options ...Options) (*API, error)

func (*API) Run

func (a *API) Run() error

type Caption

type Caption struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Image     uint      `gorm:"type:int;not null;unique_index:idx_captions_image" json:"image"`
	Message   string    `gorm:"type:varchar(255);not null" json:"message"`
	PostedBy  uint      `gorm:"type:int;not null" json:"posted_by"`
	Votes     []Vote    `gorm:"foreignkey:Caption" json:"votes"`
}

type Image

type Image struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `json:"created_at"`
	Slug      string    `gorm:"type:varchar(255);not null;unique;unique_index:idx_images_slug" json:"slug"`
	Source    string    `gorm:"type:varchar(255);not null" json:"source"`
	PostedBy  uint      `gorm:"type:int;not null;unique_index:idx_images_postedby" json:"posted_by"`
	Votes     []Vote    `gorm:"foreignkey:Image" json:"votes"`
	Captions  []Caption `gorm:"foreignkey:Image" json:"captions"`
}

type Options

type Options struct {
	Addr    string
	Version string
	Server  *http.Server
	Router  *mux.Router
	DB      *gorm.DB
	Logger  *log.Logger
	DBname  string
	DBhost  string
	DBuser  string
	DBpass  string
	DBssl   string
	Debug   bool
}

type User

type User struct {
	gorm.Model
	Username       string    `gorm:"type:varchar(20);not null;unique;unique_index:idx_users_username" json:"username"`
	Email          string    `gorm:"type:varchar(255);not null;unique;unique_index:idx_users_email" json:"email"`
	EmailConfirmed bool      `gorm:"type:boolean" json:"emailconfirmed"`
	Password       string    `gorm:"type:varchar(255);not null" json:"password,omitempty"`
	Votes          []Vote    `gorm:"foreignkey:PostedBy" json:"votes"`
	Captions       []Caption `gorm:"foreignkey:PostedBy" json:"captions"`
	Images         []Image   `gorm:"foreignkey:PostedBy" json:"images"`
}

type Vote

type Vote struct {
	gorm.Model
	PostedBy uint `gorm:"type:int;not null;index:idx_votes_posted_by" json:"posted_by"`
	Value    bool `gorm:"type:boolean;not null" json:"value"`
	Caption  uint `gorm:"type:int" json:"caption"`
	Image    uint `gorm:"type:int" json:"image"`
}

Jump to

Keyboard shortcuts

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