func (r *MockOinkRepo) Create(o model.Oink) (model.Oink, error) { r.lock.Lock() defer r.lock.Unlock() o.ID = strconv.Itoa(len(r.oinks)) o.CreationTime = time.Now() r.oinks = append(r.oinks, o) return o, nil }
func (r *CQLOinkRepo) Create(o model.Oink) (model.Oink, error) { r.lock.RLock() defer r.lock.RUnlock() if !r.initialized { return model.Oink{}, errors.New("Uninitialized repo") } o.ID = uuid.NewV4().String() o.CreationTime = time.Now() err := r.session.Query( "INSERT INTO oinker.oinks (kind, id, content, created_at, handle) "+ "VALUES (?, ?, ?, ?, ?)", "oink", o.ID, o.Content, gocql.UUIDFromTime(o.CreationTime), o.Handle, ).Exec() if err != nil { return model.Oink{}, fmt.Errorf("Inserting oink (%+v): %s", o, err) } return o, nil }