models

package
v0.0.32-0...-5ee999a Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2021 License: GPL-2.0, GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database interface {
	AddURL(*URL) error
	RemoveURL(*URL) error
	IncrementURLVisits(shortURL string) error
	GetURL(shortURL string) (*URL, error)
	GetURLs(*User) ([]*URL, error)

	AddUser(*User) error
	RemoveUser(*User) error
	IncrementUserURLsCount(*User) error
	DecrementUserURLsCount(*User) error
	GetUser(*User) (*User, error)

	AddURLData(*URLData) error
	RemoveURLData(*URL) error
	GetURLData(*URL) ([]*URLData, error)

	AddSession(*Session) error
	RemoveSession(*Session) error
	GetSession(*Session) (*Session, error)

	GetUsers() ([]*User, error)
	GetAllURLs() ([]*URL, error)
	GetSessions() ([]*Session, error)
}

Database represents a database that can be used for the program

type SQLite

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

SQLite represents a sqlite database for the program

func NewSQLiteDB

func NewSQLiteDB() *SQLite

NewSQLiteDB returns a singleton SQLite instance

func (*SQLite) AddSession

func (s *SQLite) AddSession(sess *Session) error

AddSession adds a new session to the database

func (*SQLite) AddURL

func (s *SQLite) AddURL(url *URL) error

AddURL add a new url entry to the database

func (*SQLite) AddURLData

func (s *SQLite) AddURLData(urlData *URLData) error

AddURLData adds data of a certain url, and returns an occurred error

func (*SQLite) AddUser

func (s *SQLite) AddUser(user *User) error

AddUser adds a user to the database

func (*SQLite) DecrementUserURLsCount

func (s *SQLite) DecrementUserURLsCount(user *User) error

DecrementUserURLsCount well its written on the box :)

func (*SQLite) GetAllURLs

func (s *SQLite) GetAllURLs() ([]*URL, error)

GetAllURLs returns a slice of available URLs to be seen by the admin only :)

func (*SQLite) GetSession

func (s *SQLite) GetSession(sess *Session) (*Session, error)

GetSession returns a specific session from the database

func (*SQLite) GetSessions

func (s *SQLite) GetSessions() ([]*Session, error)

GetSession returns a slice of available sessions to be seen by the admin only :)

func (*SQLite) GetURL

func (s *SQLite) GetURL(shortURL string) (*URL, error)

GetURL returns the full URL of a short URL

func (*SQLite) GetURLData

func (s *SQLite) GetURLData(url *URL) ([]*URLData, error)

GetURLData returns a slice of URLData of the given URL and an occurred error

func (*SQLite) GetURLs

func (s *SQLite) GetURLs(user *User) ([]*URL, error)

GetURLs returns a map that has short URLs of the given user

func (*SQLite) GetUser

func (s *SQLite) GetUser(user *User) (*User, error)

GetUser returns an existing user from the database

func (*SQLite) GetUsers

func (s *SQLite) GetUsers() ([]*User, error)

GetUsers returns a slice of available users to be seen by the admin only :)

func (*SQLite) IncrementURLVisits

func (s *SQLite) IncrementURLVisits(shortUrl string) error

IncrementURLVisits well its written in the box :)

func (*SQLite) IncrementUserURLsCount

func (s *SQLite) IncrementUserURLsCount(user *User) error

IncrementUserURLsCount well its written on the box :)

func (*SQLite) RemoveSession

func (s *SQLite) RemoveSession(sess *Session) error

RemoveSession a specific session from the database

func (*SQLite) RemoveURL

func (s *SQLite) RemoveURL(url *URL) error

RemoveURL removes a URL from the database

func (*SQLite) RemoveURLData

func (s *SQLite) RemoveURLData(url *URL) error

RemoveURLData removes all the data of a given URL, and returns an occurred error

func (*SQLite) RemoveUser

func (s *SQLite) RemoveUser(user *User) error

RemoveUser removes the given user from the database

type Session

type Session struct {
	UserEmail string
	Token     string
	ExpiresAt time.Time
	Alter     bool
}

Session defines session's properties(of a registered user)

type URL

type URL struct {
	Short     string
	FullURL   string
	Created   string
	Visits    int
	UserEmail string
	Alter     bool
	VisitIP   string
}

URL defines the properties of a certain URL

type URLData

type URLData struct {
	ShortURL      string
	IP            string
	UserAgent     string
	VisitLocation string
	VisitTime     string
	Alter         bool
}

URLData defines the properties of URL's tracking data

type User

type User struct {
	Email   string
	Avatar  string
	Created string
	NumURLs int
	Alter   bool
}

User defines the properties of a user

Jump to

Keyboard shortcuts

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