data

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultURLTitle = "No title (edit to change)"
)

Variables

View Source
var (
	ErrDatabaseAlreadyOpen = errors.New("database is already open")
	ErrNotFound            = errors.New("object not found")
	ErrDuplicateKey        = errors.New("duplicate key")
)
View Source
var ErrSettingsExists = errors.New("settings object already exists")
View Source
var ErrUserExists = errors.New("user already exists")

Functions

func BackupHandler

func BackupHandler(w http.ResponseWriter, req *http.Request) error

func CreatePageIndexes

func CreatePageIndexes(perPage int) error

func DBWithLock

func DBWithLock(fn func(*bolt.DB))

DBWithLock runs func fn with the global db object. Locked so nothing else can use the DB while migrations are running.

func DeleteAPITokens

func DeleteAPITokens() error

func DeleteURL

func DeleteURL(url *URL) error

func HACKCreatePageIndexes

func HACKCreatePageIndexes(perPage int, tx *bolt.Tx) error

func MustInit

func MustInit(cfg *config.Config)

func NewPageIndexPaginator

func NewPageIndexPaginator(page int) (*pageIndexPaginator, error)

func NewQuery

func NewQuery(q string) *query

func RunWithBucketForType

func RunWithBucketForType(tx *bolt.Tx, m interface{}, fn func(*bolt.Bucket) error) error

RunWithBucketForType takes a *bolt.Tx and will find the bucket for type m and then run will run the func fn with the bucket (if found). If no bucket is registered for type m, an error is returned.

Types

type APIToken

type APIToken struct {
	ID        uuid.UUID `json:"id"`
	Token     uuid.UUID `json:"token"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func CreateAPIToken

func CreateAPIToken() (*APIToken, error)

func GetAPIToken

func GetAPIToken() (*APIToken, error)

type AllURLGetter

type AllURLGetter struct{}

func (AllURLGetter) GetURLs

func (AllURLGetter) GetURLs(tx *bolt.Tx) ([]*URL, error)

type CreateTagOptions

type CreateTagOptions struct {
	Name string
}

type CreateURLOptions

type CreateURLOptions struct {
	URL     string
	Tags    string
	Private bool
}

CreateURLOptions is passed into CreateURL from the http handler to initiate a url creation

type FavURLGetter

type FavURLGetter struct{}

func (FavURLGetter) GetURLs

func (FavURLGetter) GetURLs(tx *bolt.Tx) ([]*URL, error)

type HTTPMetadataFetcher

type HTTPMetadataFetcher struct{}

func (HTTPMetadataFetcher) FetchMetadata

func (HTTPMetadataFetcher) FetchMetadata(url string) (PageMeta, error)

Returns the page title or an error. If there is an error, the url is returned as well.

type InitializeInstanceOptions

type InitializeInstanceOptions struct {
	Email       string `schema:"email"`
	Password    string `schema:"password"`
	Private     bool   `schema:"private"`
	EmbedPhotos bool   `schema:"embedphotos"`
	EmbedVideos bool   `schema:"embedvideos"`
	PerPage     int    `schema:"perpage"`
}

type PageIndex

type PageIndex struct {
	URLIDs     []uuid.UUID `json:"url_ids"`
	TotalPages int         `json:"total_pages"`
	PerPage    int         `json:"per_page"`

	URLs []*URL `json:"-"`
}

PageIndex is a quick and dirty hack to cache the URL pages in bolt

func GetPageIndexByPage

func GetPageIndexByPage(page int) (*PageIndex, error)

func GetPageIndexes

func GetPageIndexes() ([]*PageIndex, error)

type PageMeta

type PageMeta struct {
	Title  string
	Status int
}

type Paginator

type Paginator interface {
	CurrentPage() int
	HasPagination() bool
	HasNext() bool
	HasPrevious() bool
	Pages() []int
	NextPage() int
	PreviousPage() int
	TotalPages() int
	URLs() []*URL
}

type PinnedTag

type PinnedTag struct {
	TagID   uuid.UUID `json:"tag_id"`
	Ordinal int       `json:"orginal"`
	Tag     *Tag      `json:"-"`
}

type PinnedTags

type PinnedTags []PinnedTag

func GetPinnedTags

func GetPinnedTags() (*PinnedTags, error)

func PinTag

func PinTag(tag *Tag) (*PinnedTags, error)

func UnpinTag

func UnpinTag(tag *Tag) (*PinnedTags, error)

type SearchURLGetter

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

func NewSearchURLGetter

func NewSearchURLGetter(query string) *SearchURLGetter

func (SearchURLGetter) GetURLs

func (s SearchURLGetter) GetURLs(tx *bolt.Tx) ([]*URL, error)

type Settings

type Settings struct {
	Private     bool      `json:"private"`
	EmbedPhotos bool      `json:"embed_photos"`
	EmbedVideos bool      `json:"embed_videos"`
	PerPage     int       `json:"per_page"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func GetSettings

func GetSettings() (*Settings, error)

func SaveSettings

func SaveSettings(opts SettingsOptions) (*Settings, error)

type SettingsOptions

type SettingsOptions struct {
	Private     bool `schema:"private"`
	EmbedPhotos bool `schema:"embedphotos"`
	EmbedVideos bool `schema:"embedvideos"`
	PerPage     int  `schema:"perpage"`
}

type SufrDB

type SufrDB struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SufrDB is a BoltDB wrapper that provides a SUFR specific interface to the DB

func New

func New(path string) (*SufrDB, error)

New creates and returns a new pointer to a SufrDB struct

func (*SufrDB) Close

func (s *SufrDB) Close()

Close will close the BoltDB instance

func (*SufrDB) Open

func (s *SufrDB) Open() error

Open will open the bolt database and panic on error

func (*SufrDB) Statsdumper

func (s *SufrDB) Statsdumper()

Runs in it's own goroutine if debug is on

type Tag

type Tag struct {
	ID        uuid.UUID   `json:"id"`
	Name      string      `json:"name"`
	URLs      []*URL      `json:"-"`
	URLIDs    []uuid.UUID `json:"url_ids"`
	CreatedAt time.Time   `json:"created_at"`
	UpdatedAt time.Time   `json:"updated_at"`
}

Tag holds the little information we have about url tags

func CreateTag

func CreateTag(opts CreateTagOptions) (*Tag, error)

func GetTag

func GetTag(id uuid.UUID) (*Tag, error)

func (*Tag) AddURL

func (t *Tag) AddURL(url *URL, tx *bolt.Tx) error

TODO: made public to help with the migration from the old db. This shouldn't be like this and I would like to find a solution

func (*Tag) GetURLs

func (t *Tag) GetURLs(_ *bolt.Tx) ([]*URL, error)

GetURLs satisfies the urlGetter interface for the URLPaginator

type URL

type URL struct {
	ID         uuid.UUID   `json:"id"`
	URL        string      `json:"url"`
	Title      string      `json:"title"`
	Notes      string      `json:"notes"`
	StatusCode int         `json:"status_code"`
	Private    bool        `json:"private"`
	Favorite   bool        `json:"favorite"`
	Tags       []*Tag      `json:"-"`
	TagIDs     []uuid.UUID `json:"tag_ids"`
	CreatedAt  time.Time   `json:"created_at"`
	UpdatedAt  time.Time   `json:"updated_at"`
}

URL is the model for a url object

func CreateURL

func CreateURL(opts CreateURLOptions, fetcher URLMetadataFetcher) (*URL, error)

func GetURL

func GetURL(id uuid.UUID) (*URL, error)

func GetURLByURL

func GetURLByURL(urlstr string) (*URL, error)

func GetURLs

func GetURLs() ([]*URL, error)

GetURLs will return a slice of *URL sorted by URL.CreatedAt desc

func UpdateURL

func UpdateURL(opts UpdateURLOptions) (*URL, error)

func (*URL) FormattedCreatedAt

func (u *URL) FormattedCreatedAt() string

FormattedCreatedAt is used in the template to display a human readable timestamp Returns a string

func (*URL) GetTagsForDisplay

func (u *URL) GetTagsForDisplay() string

func (*URL) HasTags

func (u *URL) HasTags() bool

HasTags returns a bool true if the url has tags assigned to it

func (*URL) IsPublic

func (u *URL) IsPublic() bool

IsPublic will return true if the url is visible to everyone (even those not logged in) This option doesn't matter is the SUFR global setting for visibility is private.

func (*URL) NotesHTML

func (u *URL) NotesHTML() template.HTML

func (*URL) ToggleFavorite

func (u *URL) ToggleFavorite() error

type URLMetadataFetcher

type URLMetadataFetcher interface {
	FetchMetadata(string) (PageMeta, error)
}

type URLPaginator

type URLPaginator struct {
	URLs []*URL
	// contains filtered or unexported fields
}

URLPaginator represents a paginated collection of URLs sorted by CreatedAt desc

func NewURLPaginator

func NewURLPaginator(page, perPage, pagePadding int, getter urlGetter) (*URLPaginator, error)

NewURLPaginator returns a filled-out *URLPaginator. returns an error if something during the read transaction fails.

func (URLPaginator) CurrentPage

func (p URLPaginator) CurrentPage() int

func (URLPaginator) HasNext

func (p URLPaginator) HasNext() bool

func (URLPaginator) HasPagination

func (p URLPaginator) HasPagination() bool

func (URLPaginator) HasPrevious

func (p URLPaginator) HasPrevious() bool

func (URLPaginator) NextPage

func (p URLPaginator) NextPage() int

func (URLPaginator) Pages

func (p URLPaginator) Pages() []int

func (URLPaginator) PreviousPage

func (p URLPaginator) PreviousPage() int

func (URLPaginator) TotalPages

func (p URLPaginator) TotalPages() int

type URLsByDateDesc

type URLsByDateDesc []*URL

func (URLsByDateDesc) Len

func (u URLsByDateDesc) Len() int

func (URLsByDateDesc) Less

func (u URLsByDateDesc) Less(i, j int) bool

func (URLsByDateDesc) Swap

func (u URLsByDateDesc) Swap(i, j int)

type UpdateURLOptions

type UpdateURLOptions struct {
	ID      uuid.UUID
	Title   string
	Notes   string
	Private bool
	Tags    string
}

UpdateURLOptions is passed into UpdateURL from the http handler to update a url

type User

type User struct {
	ID        uuid.UUID `json:"id"`
	Email     string    `json:"email"`
	Password  string    `json:"password"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func CreateUser

func CreateUser(opts UserOptions) (*User, error)

CreateUser will create the global user account. This is used to login and run api queries. There can only be one user in the system, so if an account exists, it will return an error.

func GetUser

func GetUser() (*User, error)

GetUser returns the sufr user used to login and perform api queries

type UserOptions

type UserOptions struct {
	Email    string `schema:"email"`
	Password string `schema:"password"`
}

type Version

type Version struct {
	Version uint `json:"version"`
}

func CreateVersion

func CreateVersion(start uint, tx *bolt.Tx) (*Version, error)

func GetVersion

func GetVersion(tx *bolt.Tx) (*Version, error)

func (*Version) Increment

func (v *Version) Increment(tx *bolt.Tx) error

Directories

Path Synopsis
Package migrations contains code that modifies data in the boltdb database as application logic changes.
Package migrations contains code that modifies data in the boltdb database as application logic changes.

Jump to

Keyboard shortcuts

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