storage

package
v0.0.0-...-12eefb5 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package storage contains utilities for connecting to persistent storage as well as repository implementations for modifying/querying data used by the server.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserNotInChannel is the error returned when performing operations specific
	// to a user within a channel where the user is not in that channel
	ErrUserNotInChannel = errors.New("user is not in any known channels")

	// ErrChannelDoesNotExist is the error returned when attempting to perform
	// operations on a channel that does not exist.
	ErrChannelDoesNotExist = errors.New("channel does not exist")
)
View Source
var ErrNoUser = errors.New("user does not exist")

ErrNoUser is the error returned when performing operations on a user that does not exist.

Functions

func Open

func Open(name string) (*sql.DB, error)

Open a connection to the server storage, if the database file does not exist, it is created and database migrations are performed.

Types

type Channels

type Channels struct {
	// contains filtered or unexported fields
}

The Channels type is responsible for querying/persisting channel information within the server storage.

func NewChannelRepository

func NewChannelRepository(db *sql.DB) *Channels

NewChannelRepository creates a new Channels instance that performs queries against the provided sql.DB instance.

func (*Channels) Create

func (repo *Channels) Create(ctx context.Context, name string) error

Create a channel with a given name.

func (*Channels) Delete

func (repo *Channels) Delete(ctx context.Context, name string) error

Delete a channel.

func (*Channels) Exists

func (repo *Channels) Exists(ctx context.Context, name string) (bool, error)

Exists asserts whether or not a specified channel exists.

func (*Channels) GetUserChannel

func (repo *Channels) GetUserChannel(ctx context.Context, name string) (string, error)

GetUserChannel returns the channel a user currently resides in.

func (*Channels) Join

func (repo *Channels) Join(ctx context.Context, name, channel string) error

Join a channel.

func (*Channels) Leave

func (repo *Channels) Leave(ctx context.Context, user, name string) error

Leave a channel.

func (*Channels) List

func (repo *Channels) List(ctx context.Context) ([]string, error)

List all available channels.

func (*Channels) Users

func (repo *Channels) Users(ctx context.Context, name string) ([]string, error)

Users returns a list of all users within a channel.

type Users

type Users struct {
	// contains filtered or unexported fields
}

The Users type is responsible for querying/persisting user information within the server storage.

func NewUserRepository

func NewUserRepository(db *sql.DB) *Users

NewUserRepository creates a new Users instance that will perform operations against the provided sql.DB instance.

func (*Users) Create

func (repo *Users) Create(ctx context.Context, name, pass string) error

Create a user, their password will be hashed using bcrypt.

func (*Users) Exists

func (repo *Users) Exists(ctx context.Context, name string) (bool, error)

Exists asserts whether or not a user exists with the provided name.

func (*Users) GetPasswordHash

func (repo *Users) GetPasswordHash(ctx context.Context, name string) ([]byte, error)

GetPasswordHash returns the password hash for a given user.

Directories

Path Synopsis
Package migrations contains code generated by go-bindata for performing database migrations.
Package migrations contains code generated by go-bindata for performing database migrations.

Jump to

Keyboard shortcuts

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