mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-28 17:50:56 +01:00
refactor: code cleanup
This commit is contained in:
@@ -2,7 +2,7 @@ package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/crawlab-team/crawlab/db/errors"
|
||||
"errors"
|
||||
"github.com/crawlab-team/crawlab/trace"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
@@ -58,7 +58,7 @@ func (col *Col) Insert(doc interface{}) (id primitive.ObjectID, err error) {
|
||||
if id, ok := res.InsertedID.(primitive.ObjectID); ok {
|
||||
return id, nil
|
||||
}
|
||||
return primitive.NilObjectID, trace.TraceError(errors.ErrInvalidType)
|
||||
return primitive.NilObjectID, trace.TraceError(errors.New("InsertedID is not ObjectID"))
|
||||
}
|
||||
|
||||
func (col *Col) InsertMany(docs []interface{}) (ids []primitive.ObjectID, err error) {
|
||||
@@ -72,7 +72,7 @@ func (col *Col) InsertMany(docs []interface{}) (ids []primitive.ObjectID, err er
|
||||
id := v.(primitive.ObjectID)
|
||||
ids = append(ids, id)
|
||||
default:
|
||||
return nil, trace.TraceError(errors.ErrInvalidType)
|
||||
return nil, trace.TraceError(errors.New("InsertedID is not ObjectID"))
|
||||
}
|
||||
}
|
||||
return ids, nil
|
||||
|
||||
@@ -2,7 +2,7 @@ package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/crawlab-team/crawlab/db/errors"
|
||||
"errors"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
)
|
||||
|
||||
@@ -15,16 +15,6 @@ type FindResultInterface interface {
|
||||
GetError() (err error)
|
||||
}
|
||||
|
||||
func NewFindResult() (fr *FindResult) {
|
||||
return &FindResult{}
|
||||
}
|
||||
|
||||
func NewFindResultWithError(err error) (fr *FindResult) {
|
||||
return &FindResult{
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
|
||||
type FindResult struct {
|
||||
col *Col
|
||||
res *mongo.SingleResult
|
||||
@@ -61,7 +51,7 @@ func (fr *FindResult) All(val interface{}) (err error) {
|
||||
ctx = fr.col.ctx
|
||||
}
|
||||
if fr.cur == nil {
|
||||
return errors.ErrNoCursor
|
||||
return errors.New("no cursor")
|
||||
}
|
||||
if !fr.cur.TryNext(ctx) {
|
||||
return ctx.Err()
|
||||
|
||||
Reference in New Issue
Block a user