models

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Door image.
	Door CommandImage = "door"

	// Light image.
	Light CommandImage = "light"

	// Outlet image.
	Outlet CommandImage = "outlet"

	// Plug image.
	Plug CommandImage = "plug"

	// Sensor image.
	Sensor CommandImage = "sensor"

	// PayloadVariable pattern.
	PayloadVariable string = "%p"
)

Variables

View Source
var (
	// ErrDuplicateEmail error.
	ErrDuplicateEmail = errors.New("models: duplicate email")

	// ErrDuplicateName error.
	ErrDuplicateName = errors.New("models: duplicate name")

	// ErrDuplicateUsername error.
	ErrDuplicateUsername = errors.New("models: duplicate username")

	// ErrInvalidCredentials error.
	ErrInvalidCredentials = errors.New("models: invalid credentials")

	// ErrInvalidValue error.
	ErrInvalidValue = errors.New("models: invalid value")

	// ErrNoRecord error.
	ErrNoRecord = errors.New("models: no matching record found")

	// ErrTimestamp error.
	ErrTimestamp = errors.New("models: invalid timestamp type")
)

Functions

func CommandCreateRules

func CommandCreateRules(form *forms.Form)

CommandCreateRules function.

func CommandUpdateRules

func CommandUpdateRules(form *forms.Form)

CommandUpdateRules function.

func UserCreateRules

func UserCreateRules(form *forms.Form)

UserCreateRules function.

func UserUpdateRules

func UserUpdateRules(form *forms.Form)

UserUpdateRules function.

Types

type Call

type Call struct {
	ID        int64      `json:"id" redis:"id"`
	CommandID int        `json:"command_id" redis:"command_id"`
	Status    CallStatus `json:"status" redis:"status"`
	Payload   string     `json:"payload" redis:"payload"`
	Output    string     `json:"output" redis:"output"`
	CreatedAt Timestamp  `json:"created_at" redis:"created_at"`
}

Call type.

func NewCall

func NewCall(command *Command) *Call

NewCall function.

type CallRepository

type CallRepository interface {
	Create(*Call) error
	Find(int64) (*Call, error)
	FindAllByCommand(*Command) ([]*Call, error)
	Update(*Call, *Call) error
	Delete(*Call) error
}

CallRepository type.

type CallStatus

type CallStatus string

CallStatus type.

const (
	// Pending status.
	Pending CallStatus = "pending"

	// InProgress status.
	InProgress CallStatus = "in_progress"

	// Completed status.
	Completed CallStatus = "completed"

	// Failed status.
	Failed CallStatus = "failed"
)

type Command

type Command struct {
	ID        int          `json:"id" redis:"id"`
	Name      string       `json:"name" redis:"name"`
	Token     string       `json:"-" redis:"token"`
	Image     CommandImage `json:"image" redis:"image"`
	Value     string       `json:"value" redis:"value"`
	CreatedAt Timestamp    `json:"created_at" redis:"created_at"`
}

Command type.

func NewCommand

func NewCommand() *Command

NewCommand function.

func (*Command) Fill

func (c *Command) Fill(form *forms.Form) *Command

Fill function.

func (*Command) Path

func (c *Command) Path(url string) string

Path function.

type CommandImage

type CommandImage string

CommandImage type.

type CommandRepository

type CommandRepository interface {
	Create(*Command, string) error
	Find(int) (*Command, error)
	FindAll() ([]*Command, error)
	Update(*Command, *Command) error
	UpdateToken(*Command, string) error
	Delete(*Command) error
}

CommandRepository type.

type RedisCallRepository

type RedisCallRepository struct {
	RedisPool      *redis.Pool
	RedisKeyPrefix string
	HistoryLimit   int
}

RedisCallRepository type.

func (*RedisCallRepository) Create

func (rcr *RedisCallRepository) Create(call *Call) error

Create function.

func (*RedisCallRepository) Delete

func (rcr *RedisCallRepository) Delete(call *Call) error

Delete function.

func (*RedisCallRepository) Find

func (rcr *RedisCallRepository) Find(id int64) (*Call, error)

Find function.

func (*RedisCallRepository) FindAllByCommand

func (rcr *RedisCallRepository) FindAllByCommand(command *Command) ([]*Call, error)

FindAllByCommand function.

func (*RedisCallRepository) Update

func (rcr *RedisCallRepository) Update(call, newCall *Call) error

Update function.

type RedisCommandRepository

type RedisCommandRepository struct {
	RedisPool      *redis.Pool
	RedisKeyPrefix string
}

RedisCommandRepository type.

func (*RedisCommandRepository) Create

func (rcr *RedisCommandRepository) Create(command *Command, token string) error

Create function.

func (*RedisCommandRepository) Delete

func (rcr *RedisCommandRepository) Delete(command *Command) error

Delete function.

func (*RedisCommandRepository) Find

func (rcr *RedisCommandRepository) Find(id int) (*Command, error)

Find function.

func (*RedisCommandRepository) FindAll

func (rcr *RedisCommandRepository) FindAll() ([]*Command, error)

FindAll function.

func (*RedisCommandRepository) Update

func (rcr *RedisCommandRepository) Update(command, newCommand *Command) error

Update function.

func (*RedisCommandRepository) UpdateToken

func (rcr *RedisCommandRepository) UpdateToken(command *Command, token string) error

UpdateToken function.

type RedisUserRepository

type RedisUserRepository struct {
	RedisPool      *redis.Pool
	RedisKeyPrefix string
}

RedisUserRepository type.

func (*RedisUserRepository) Authenticate

func (rur *RedisUserRepository) Authenticate(usernameOrEmail, password string) (*User, error)

Authenticate function.

func (*RedisUserRepository) AuthenticateByRememberToken

func (rur *RedisUserRepository) AuthenticateByRememberToken(id int, token string) (*User, error)

AuthenticateByRememberToken function.

func (*RedisUserRepository) Create

func (rur *RedisUserRepository) Create(user *User) error

Create function.

func (*RedisUserRepository) Delete

func (rur *RedisUserRepository) Delete(user *User) error

Delete function.

func (*RedisUserRepository) Find

func (rur *RedisUserRepository) Find(id int) (*User, error)

Find function.

func (*RedisUserRepository) FindAll

func (rur *RedisUserRepository) FindAll() ([]*User, error)

FindAll function.

func (*RedisUserRepository) Update

func (rur *RedisUserRepository) Update(user, newUser *User) error

Update function.

func (*RedisUserRepository) UpdateRememberToken

func (rur *RedisUserRepository) UpdateRememberToken(user *User, token string) error

UpdateRememberToken function.

type Timestamp

type Timestamp time.Time

Timestamp type.

func (Timestamp) MarshalJSON

func (t Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON function.

func (Timestamp) RedisArg

func (t Timestamp) RedisArg() interface{}

RedisArg function.

func (*Timestamp) RedisScan

func (t *Timestamp) RedisScan(src interface{}) error

RedisScan function.

type User

type User struct {
	ID            int       `json:"id" redis:"id"`
	Username      string    `json:"username" redis:"username"`
	Email         string    `json:"email" redis:"email"`
	Password      []byte    `json:"-" redis:"password"`
	RememberToken string    `json:"-" redis:"remember_token"`
	IsEnabled     bool      `json:"is_enabled" redis:"is_enabled"`
	CreatedAt     Timestamp `json:"created_at" redis:"created_at"`
}

User type.

func NewUser

func NewUser() *User

NewUser function.

func (*User) Fill

func (u *User) Fill(form *forms.Form) *User

Fill function.

func (*User) Gravatar

func (u *User) Gravatar(size int) string

Gravatar function.

func (*User) RememberCookie

func (u *User) RememberCookie() []byte

RememberCookie function.

type UserRepository

type UserRepository interface {
	Create(*User) error
	Find(int) (*User, error)
	FindAll() ([]*User, error)
	Update(*User, *User) error
	UpdateRememberToken(*User, string) error
	Authenticate(string, string) (*User, error)
	AuthenticateByRememberToken(int, string) (*User, error)
	Delete(*User) error
}

UserRepository type.

Jump to

Keyboard shortcuts

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