-
Notifications
You must be signed in to change notification settings - Fork 653
/
collection.go
46 lines (40 loc) · 1.56 KB
/
collection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package mongodb
import (
"errors"
"go.mongodb.org/mongo-driver/mongo"
)
type GetCollectionInterface interface {
getCollection(collectionType int) (*mongo.Collection, error)
}
type GetCollectionStruct struct{}
var GetCollectionClient GetCollectionInterface = &GetCollectionStruct{}
// getCollection function returns the appropriate DB collection based on the collection value passed
func (g *GetCollectionStruct) getCollection(collectionType int) (*mongo.Collection, error) {
mongoClient := Client
switch collectionType {
case ChaosInfraCollection:
return mongoClient.(*MongoClient).ChaosInfraCollection, nil
case ChaosExperimentCollection:
return mongoClient.(*MongoClient).ChaosExperimentCollection, nil
case ChaosExperimentRunsCollection:
return mongoClient.(*MongoClient).ChaosExperimentRunsCollection, nil
case ChaosHubCollection:
return mongoClient.(*MongoClient).ChaosHubCollection, nil
case ImageRegistryCollection:
return mongoClient.(*MongoClient).ImageRegistryCollection, nil
case ServerConfigCollection:
return mongoClient.(*MongoClient).ServerConfigCollection, nil
case UserCollection:
return mongoClient.(*MongoClient).UserCollection, nil
case ProjectCollection:
return mongoClient.(*MongoClient).ProjectCollection, nil
case GitOpsCollection:
return mongoClient.(*MongoClient).GitOpsCollection, nil
case EnvironmentCollection:
return mongoClient.(*MongoClient).EnvironmentCollection, nil
case ChaosProbeCollection:
return mongoClient.(*MongoClient).ChaosProbeCollection, nil
default:
return nil, errors.New("unknown collection name")
}
}