// AddKey will add a key to the gallery func AddKey(gid int) (err error) { // start transaction tx, err := u.Storm.Begin(true) if err != nil { return } defer tx.Rollback() var gallery m.GalleryType err = tx.One("ID", gid, &gallery) if err != nil { return } sort.Sort(gallery.Keys) key := m.KeyType{ Key: u.GenerateRandomPassword(20), Created: time.Now(), } gallery.Keys = append(gallery.Keys, key) err = tx.Save(&gallery) if err != nil { return } // commit tx.Commit() return }