Documentation ¶
Overview ¶
Package db contains all interfaces to the databases used by Ponzu, including exported functions to easily manage addons, users, indices, search, content, and configuration.
Index ¶
- Constants
- Variables
- func AddBucket(name string)
- func Addon(key string) ([]byte, error)
- func AddonAll() [][]byte
- func AddonExists(key string) bool
- func Backup(ctx context.Context, res http.ResponseWriter) error
- func CacheControl(next http.Handler) http.HandlerFunc
- func Close()
- func Config(key string) ([]byte, error)
- func ConfigAll() ([]byte, error)
- func ConfigCache(key string) interface{}
- func Content(target string) ([]byte, error)
- func ContentAll(namespace string) [][]byte
- func ContentBySlug(slug string) (string, []byte, error)
- func ContentMulti(targets []string) ([][]byte, error)
- func CurrentUser(req *http.Request) ([]byte, error)
- func DeleteAddon(key string) error
- func DeleteContent(target string) error
- func DeleteIndex(namespace, key string) error
- func DeleteUpload(target string) error
- func DeleteUser(email string) error
- func DropIndex(namespace string) error
- func Index(namespace, key string) ([]byte, error)
- func Init()
- func InitSearchIndex()
- func InvalidateCache() error
- func IsValidID(id string) bool
- func LoadCacheConfig() error
- func NewEtag() string
- func PutConfig(key string, value interface{}) error
- func Query(namespace string, opts QueryOptions) (int, [][]byte)
- func RecoveryKey(email string) (string, error)
- func SetAddon(data url.Values, kind interface{}) error
- func SetConfig(data url.Values) error
- func SetContent(target string, data url.Values) (int, error)
- func SetIndex(namespace, key string, value interface{}) error
- func SetRecoveryKey(email string) (string, error)
- func SetUpload(target string, data url.Values) (int, error)
- func SetUser(usr *user.User) (int, error)
- func SortContent(namespace string)
- func Store() *bolt.DB
- func SystemInitComplete() bool
- func UpdateContent(target string, data url.Values) (int, error)
- func UpdateUser(usr, updatedUsr *user.User) error
- func Upload(target string) ([]byte, error)
- func UploadAll() [][]byte
- func UploadBySlug(slug string) ([]byte, error)
- func User(email string) ([]byte, error)
- func UserAll() ([][]byte, error)
- type QueryOptions
Constants ¶
const ( // DefaultMaxAge provides a 2592000 second (30-day) cache max-age setting DefaultMaxAge = int64(60 * 60 * 24 * 30) )
Variables ¶
var ( // ErrNoAddonExists indicates that there was not addon found in the db ErrNoAddonExists = errors.New("No addon exists.") )
var ErrNoUserExists = errors.New("Error. No user exists.")
ErrNoUserExists is used for the db to report to admin user of non-existing user
var ErrUserExists = errors.New("Error. User exists.")
ErrUserExists is used for the db to report to admin user of existing user
Functions ¶
func AddBucket ¶
func AddBucket(name string)
AddBucket adds a bucket to be created if it doesn't already exist
func Addon ¶
Addon looks for an addon by its addon_reverse_dns as the key and returns the []byte as json representation of an addon
func AddonExists ¶
AddonExists checks if there is an existing addon stored. The key is an the value at addon_reverse_dns
func Backup ¶
func Backup(ctx context.Context, res http.ResponseWriter) error
Backup writes a snapshot of the system.db database to an HTTP response. The output is discarded if we get a cancellation signal.
func CacheControl ¶
func CacheControl(next http.Handler) http.HandlerFunc
CacheControl sets the default cache policy on static asset responses
func Close ¶
func Close()
Close exports the abillity to close our db file. Should be called with defer after call to Init() from the same place.
func ConfigCache ¶
func ConfigCache(key string) interface{}
ConfigCache is a in-memory cache of the Configs for quicker lookups 'key' is the JSON tag associated with the config field
func Content ¶
Content retrives one item from the database. Non-existent values will return an empty []byte The `target` argument is a string made up of namespace:id (string:int)
func ContentAll ¶
ContentAll retrives all items from the database within the provided namespace
func ContentBySlug ¶
ContentBySlug does a lookup in the content index to find the type and id of the requested content. Subsequently, issues the lookup in the type bucket and returns the the type and data at that ID or nil if nothing exists.
func ContentMulti ¶
ContentMulti returns a set of content based on the the targets / identifiers provided in Ponzu target string format: Type:ID NOTE: All targets should be of the same type
func CurrentUser ¶
CurrentUser extracts the user from the request data and returns the current user from the db
func DeleteAddon ¶
DeleteAddon removes an addon from the db by its key, the addon_reverse_dns
func DeleteContent ¶
DeleteContent removes an item from the database. Deleting a non-existent item will return a nil error.
func DeleteIndex ¶
DeleteIndex removes the key and value from the namespace provided and will return an error if it fails. It will return nil if there was no key/value in the index to delete.
func DeleteUpload ¶
DeleteUpload removes the value for an upload at its key id, based on the target provided i.e. __uploads:{id}
func DeleteUser ¶
DeleteUser deletes a user from the db by email
func Init ¶
func Init()
Init creates a db connection, initializes db with required info, sets secrets
func InitSearchIndex ¶
func InitSearchIndex()
InitSearchIndex initializes Search Index for search to be functional This was moved out of db.Init and put to main(), because addon checker was initializing db together with search indexing initialisation in time when there were no item.Types defined so search index was always empty when using addons. We still have no guarentee whatsoever that item.Types is defined Should be called from a goroutine after SetContent is successful (SortContent requirement)
func InvalidateCache ¶
func InvalidateCache() error
InvalidateCache sets a new Etag for http responses
func IsValidID ¶
IsValidID checks that an ID from a DB target is valid. ID should be an integer greater than 0. ID of -1 is special for new posts, not updates. IDs start at 1 for auto-incrementing
func LoadCacheConfig ¶
func LoadCacheConfig() error
LoadCacheConfig loads the config into a cache to be accessed by ConfigCache()
func Query ¶
func Query(namespace string, opts QueryOptions) (int, [][]byte)
Query retrieves a set of content from the db based on options and returns the total number of content in the namespace and the content
func RecoveryKey ¶
RecoveryKey gets a previously set recovery key to verify an email address submitted in order to recover/reset an account password
func SetAddon ¶
SetAddon stores the values of an addon into the __addons bucket with a the `addon_reverse_dns` field used as the key. `kind` is the interface{} type for the provided addon (as in the result of calling addon.Types[id])
func SetContent ¶
SetContent inserts/replaces values in the database. The `target` argument is a string made up of namespace:id (string:int)
func SetIndex ¶
SetIndex sets a key/value pair within the namespace provided and will return an error if it fails
func SetRecoveryKey ¶
SetRecoveryKey generates and saves a random secret key to verify an email address submitted in order to recover/reset an account password
func SortContent ¶
func SortContent(namespace string)
SortContent sorts all content of the type supplied as the namespace by time, in descending order, from most recent to least recent Should be called from a goroutine after SetContent is successful
func SystemInitComplete ¶
func SystemInitComplete() bool
SystemInitComplete checks if there is at least 1 admin user in the db which would indicate that the system has been configured to the minimum required.
func UpdateContent ¶
UpdateContent updates/merges values in the database. The `target` argument is a string made up of namespace:id (string:int)
func UpdateUser ¶
UpdateUser sets key:value pairs in the db for existing user settings
func UploadAll ¶
func UploadAll() [][]byte
UploadAll returns a [][]byte containing all upload data from the system
func UploadBySlug ¶
UploadBySlug returns the value for an upload by its slug
Types ¶
type QueryOptions ¶
QueryOptions holds options for a query