func (s *Section) AddAudio(articleId string, uploadFile multipart.File) error { shard := model.GetShardID(articleId) audio, err := audio.Create(articleId, s.Id, uploadFile) if err != nil { return err } s.AudiosId = append([]string{audio.Id}, s.AudiosId...) _, err = gorethink.Table("sections" + shard).Get(s.Id).Update(s).RunWrite(model.Rethink) return err }
func Get(articleId string, id string) (*Section, error) { shard := model.GetShardID(articleId) rows, err := gorethink.Table("sections" + shard).Get(id).Run(model.Rethink) if err != nil { return nil, err } defer rows.Close() if rows.IsNil() { return nil, model.ErrNotFound } s := &Section{} err = rows.One(s) if err != nil { return nil, err } s.Id = id return s, nil }