database

package
v0.0.0-...-35f9e00 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: Unlicense Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheDB

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

func NewCacheDB

func NewCacheDB(connectionUrl string) (*CacheDB, error)

func (CacheDB) AddUser

func (c CacheDB) AddUser(username string, hashedPassword string) (string, error)

func (CacheDB) GetUser

func (c CacheDB) GetUser(token string) (*User, error)

func (CacheDB) Shutdown

func (c CacheDB) Shutdown(context.Context) error

type Cacher

type Cacher interface {
	AddUser(username string, hashedPassword string) (token string, err error)
	GetUser(token string) (*User, error)
	Shutdown(context.Context) error
}

type MainDB

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

func NewMainDB

func NewMainDB(connectionUrl string) (*MainDB, error)

func (MainDB) AddMessage

func (d MainDB) AddMessage(m *Message) (string, error)

func (MainDB) AddUser

func (d MainDB) AddUser(u *User) error

func (MainDB) DeleteMessage

func (d MainDB) DeleteMessage(id string) error

func (MainDB) GetLastPublicMessages

func (d MainDB) GetLastPublicMessages(skip int) (MessagesOut, error)

func (MainDB) GetMessage

func (d MainDB) GetMessage(id string) (MessageOut, error)

func (MainDB) GetUser

func (d MainDB) GetUser(username string) (UserOut, error)

func (MainDB) GetUserMessages

func (d MainDB) GetUserMessages(ownerId string) (MessagesOut, error)

func (*MainDB) Shutdown

func (d *MainDB) Shutdown(ctx context.Context) error

func (MainDB) UpdateMessage

func (d MainDB) UpdateMessage(id string, m *Message) error

type Message

type Message struct {
	OwnerId       string `json:"owner_id" bson:"owner_id"`
	Content       string `json:"content" bson:"content"`
	IsPrivate     bool   `json:"is_private" bson:"is_private"`
	EncodingType  string `json:"encoding_type" bson:"encoding_type"`
	Password      string `json:"password" bson:"password"`
	OnlyOwnerView bool   `json:"only_owner_view" bson:"only_owner_view"`
	IsAnon        bool   `json:"is_anon" bson:"is_anon"`
	IsOneTime     bool   `json:"is_one_time" bson:"is_one_time"`
}

type MessageOut

type MessageOut struct {
	Id            primitive.ObjectID `json:"id" bson:"_id"`
	OwnerId       string             `json:"owner_id,omitempty" bson:"owner_id"`
	Content       string             `json:"content" bson:"content"`
	IsPrivate     bool               `json:"is_private" bson:"is_private"`
	EncodingType  string             `json:"encoding_type" bson:"encoding_type"`
	Password      string             `json:"password,omitempty" bson:"password"`
	OnlyOwnerView bool               `json:"only_owner_view" bson:"only_owner_view"`
	IsAnon        bool               `json:"is_anon" bson:"is_anon"`
	IsOneTime     bool               `json:"is_one_time" bson:"is_one_time"`
}

type MessagesDB

type MessagesDB interface {
	AddMessage(m *Message) (id string, err error)
	GetMessage(id string) (MessageOut, error)
	GetLastPublicMessages(limit int) (MessagesOut, error)
	GetUserMessages(ownerId string) (MessagesOut, error)
	UpdateMessage(id string, m *Message) error
	DeleteMessage(id string) error
}

type MessagesOut

type MessagesOut []MessageOut

type Storager

type Storager interface {
	UsersDB
	MessagesDB
	Shutdown(context.Context) error
}

type User

type User struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type UserOut

type UserOut struct {
	Id       primitive.ObjectID `bson:"_id"`
	Username string             `json:"username"`
	Password string             `json:"password"`
}

type UsersDB

type UsersDB interface {
	AddUser(u *User) error
	GetUser(username string) (UserOut, error)
}

Jump to

Keyboard shortcuts

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