// Get Returns template with gien name func (u Utemplates) Get(templateName string) *UserTemplate { templ := &UserTemplate{} err := boltdb.DB(u.BoltDBMain, u.DataEncoding).Bucket(u.BotlDBUserTemplatesBacket).Get(templateName, templ) if err != nil { log.Println("Can't load user template:", err) return nil } return templ }
// GetAll Get all tamplates with their names func (u Utemplates) GetAll() (map[string]UserTemplate, error) { templs := map[string]UserTemplate{} ut, err := boltdb.DB(u.BoltDBMain, u.DataEncoding).Bucket(u.BotlDBUserTemplatesBacket).GetAll(&UserTemplate{}) if err != nil { return templs, err } for k, v := range ut { templs[k] = *v.(*UserTemplate) } return templs, nil }
//Delete Deletes template from db func (u Utemplates) Delete(templateName string) { boltdb.DB(u.BoltDBMain, u.DataEncoding).Bucket(u.BotlDBUserTemplatesBacket).Delete(templateName) }
// Set Creates new or update entry for template func (u Utemplates) Set(templateName string, templ UserTemplate) { boltdb.DB(u.BoltDBMain, u.DataEncoding).Bucket(u.BotlDBUserTemplatesBacket).Set(templateName, templ) }