data

package
v0.0.0-...-9f8fbe6 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Db *sql.DB

Db is a handler of database connection

Functions

func Encrypt

func Encrypt(plaintext string) (cryptext string)

Encrypt hash plaintext with SHA-1

func SessionDeleteAll

func SessionDeleteAll() (err error)

SessionDeleteAll delete all sessions from database

func UserDeleteAll

func UserDeleteAll() (err error)

UserDeleteAll delete all users

Types

type Post

type Post struct {
	ID        int
	UUID      string
	Body      string
	UserID    int
	ThreadID  int
	CreatedAt time.Time
}

Post struct

func (*Post) CreatedAtDate

func (post *Post) CreatedAtDate() string

CreatedAtDate formats the CreatedAt date to display nicely on the screen

func (*Post) User

func (post *Post) User() (user User)

User gets a user who wrote the post

type Session

type Session struct {
	ID        int
	UUID      string
	Email     string
	UserID    int
	CreatedAt time.Time
}

Session struct

func (*Session) Check

func (session *Session) Check() (valid bool, err error)

Check if session is valid in the database

func (*Session) DeleteByUUID

func (session *Session) DeleteByUUID() (err error)

DeleteByUUID deletes session from database

func (*Session) User

func (session *Session) User() (user User, err error)

User gets user from the session

type Thread

type Thread struct {
	ID        int
	UUID      string
	Topic     string
	UserID    int
	CreatedAt time.Time
}

Thread struct

func ThreadByUUID

func ThreadByUUID(uuid string) (conv Thread, err error)

ThreadByUUID return a thread by the UUID

func Threads

func Threads() (threads []Thread, err error)

Threads gets all threads in the database and return them

func (*Thread) CreatedAtDate

func (thread *Thread) CreatedAtDate() string

CreatedAtDate formats the CreatedAt date to display nicely on the screen

func (*Thread) NumReplies

func (thread *Thread) NumReplies() (count int)

NumReplies gets the number of posts in a thread

func (*Thread) Posts

func (thread *Thread) Posts() (posts []Post, err error)

Posts get all posts to a thread

func (*Thread) User

func (thread *Thread) User() (user User)

User gets a user who started this thread

type User

type User struct {
	ID        int
	UUID      string
	Name      string
	Email     string
	Password  string
	CreatedAt time.Time
}

User struct

func UserByEmail

func UserByEmail(email string) (user User, err error)

UserByEmail gets a single user given the email

func UserByUUID

func UserByUUID(uuid string) (user User, err error)

UserByUUID gets a single user given the UUID

func Users

func Users() (users []User, err error)

Users gets all users in the database and return them

func (*User) Create

func (user *User) Create() (err error)

Create a new user, save user info into the database

func (*User) CreatePost

func (user *User) CreatePost(conv Thread, body string) (post Post, err error)

CreatePost creates a new post to a thread

func (*User) CreateSession

func (user *User) CreateSession() (session Session, err error)

CreateSession create a new session for an existing user

func (*User) CreateThread

func (user *User) CreateThread(topic string) (conv Thread, err error)

CreateThread create a new thread

func (*User) Delete

func (user *User) Delete() (err error)

Delete user from database

func (*User) Session

func (user *User) Session() (session Session, err error)

Session gets session for an existing user

func (*User) Update

func (user *User) Update() (err error)

Update user info in the database

Jump to

Keyboard shortcuts

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