models

package
v0.0.0-...-588f2ff Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2016 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//CtxBuild is the key that stores Context in all the requests.
	CtxBuild = "buildCtx"

	//TaskTable is the name of the database table for tasks.
	TaskTable = "tasks"

	//SessionTable is the name of  the database table for sessions
	SessionTable = "sessions"

	//UserTable is the name of the databse table for users.
	UserTable = "users"

	//DBTag is the name of the struct tag used by the store
	DBTag = "store"
)

Variables

This section is empty.

Functions

func Count

func Count(store *db.DB, table string) (int, error)

Count counts the number of rows in a table named table.

func CreateSession

func CreateSession(store *db.DB, s *Session) error

CreateSession creates a new database record for the session s object. This sets CreatedOn and UpdatedOn fieds to time.Now().

func CreateUser

func CreateUser(store *db.DB, u *User) error

CreateUser creates a new record in the userstable. The Password field is hashed before being stored. The Username is sanitized before storing it to the database( Don't trust abybody).

func DeleteSession

func DeleteSession(store *db.DB, s *Session) error

DeleteSession deletes a session record which matches key.

func ExecModel

func ExecModel(store *db.DB, model interface{}, query db.Query) (sql.Result, error)

ExecModel executes the given query. If the guery requires data from the model then the data is also taken care of.

This provides a simple abstraction for repetitive dababase query execution. It supports transactions.

func HashPassword

func HashPassword(pass []byte) ([]byte, error)

HashPassword hash pass using bcrypt.

func QueryRowModel

func QueryRowModel(store *db.DB, model interface{}, query db.Query) *sql.Row

QueryRowModel use the model to query for one row.

func Sanitize

func Sanitize(src string) string

Sanitize sanitizes src to avoid SQL injections.

func UpdateSession

func UpdateSession(store *db.DB, s *Session) error

UpdateSession updates a ratabase record for session whose key matches key. Only two fields are updated, the data and updated_on field.

func VerifyPass

func VerifyPass(hash, pass []byte) error

VerifyPass verifies that the hash is the hash of pass using bcrypt.

Types

type BuildArtifact

type BuildArtifact interface {
	User() string
	Project() string
	Source() string
}

BuildArtifact is an interface which defines a buildable command.

type BuildTask

type BuildTask struct {
	ID        int64     `store:"id"`
	UUID      string    `store:"uuid"`
	Done      bool      `store:"done"`
	User      int64     `store:"user_id"`
	Project   int64     `store:"project_id"`
	Source    string    `store:"source"`
	CreatedAt time.Time `store:"created_on"`
	UpdateAt  time.Time `store:"updated_on"`
}

BuildTask is a task for building a project.

type Config

type Config struct {
	Port       int
	WorkDir    string
	PublishDir string
}

Config configuration object.

type Context

type Context struct {
	Config *Config
	View   views.View
}

Context holda important information that can be used by diffenet components of the application.

func (*Context) HTML

func (ctx *Context) HTML(tpl string, data interface{}, w http.ResponseWriter,
	status int) error

type Project

type Project struct {
	ID        int       `store:"id"`
	Name      string    `store:"name"`
	UserID    int       `store:"user_id"`
	CreatedAt time.Time `store:"created_at"`
	UpdatedAt time.Time `store:"updated_at"`
}

Project represent a project.

type Session

type Session struct {
	Key       string `store:"key"`
	Data      []byte `store:"data"`
	CreatedOn time.Time
	UpdatedOn time.Time
	ExpiresOn time.Time `store:"expires_on"`
}

Session stores http session information.

func FindSessionByKey

func FindSessionByKey(store *db.DB, s *Session) (*Session, error)

FindSessionByKey queries the databse for session with key field key.

type User

type User struct {
	ID        int64     `store:"id"`
	Name      string    `store:"username"`
	Email     string    `store:"email"`
	Password  []byte    `store:"password"`
	CreatedAt time.Time `store:"created_on"`
	UpdatedAt time.Time `store:"updated_on"`
}

User represent the application user. It stores important information about the user.

The Name, Email and ID fields are all unique. Password is a hashed password, hashed using bcrypt algorithm.

func FindUserByEmail

func FindUserByEmail(store *db.DB, email string) (*User, error)

FindUserByEmail retrieves the user record with the matching email address.

Jump to

Keyboard shortcuts

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