Documentation ¶
Index ¶
- Constants
- Variables
- func MongoConnection() (*mongo.Client, error)
- type Audit
- type AuthConfig
- type GetCollectionInterface
- type GetCollectionStruct
- type MongoClient
- type MongoInterface
- type MongoOperations
- func (m *MongoOperations) Aggregate(ctx context.Context, collectionType int, pipeline interface{}, ...) (*mongo.Cursor, error)
- func (m *MongoOperations) CountDocuments(ctx context.Context, collectionType int, query bson.D, ...) (int64, error)
- func (m *MongoOperations) Create(ctx context.Context, collectionType int, document interface{}) error
- func (m *MongoOperations) CreateMany(ctx context.Context, collectionType int, documents []interface{}) error
- func (m *MongoOperations) Delete(ctx context.Context, collectionType int, query bson.D, ...) (*mongo.DeleteResult, error)
- func (m *MongoOperations) Get(ctx context.Context, collectionType int, query bson.D) (*mongo.SingleResult, error)
- func (m *MongoOperations) GetAuthConfig(ctx context.Context, key string) (*AuthConfig, error)
- func (m *MongoOperations) GetCollection(collectionType int) (*mongo.Collection, error)
- func (m *MongoOperations) List(ctx context.Context, collectionType int, query bson.D, ...) (*mongo.Cursor, error)
- func (m *MongoOperations) ListCollection(ctx context.Context, mclient *mongo.Client) ([]string, error)
- func (m *MongoOperations) ListDataBase(ctx context.Context, mclient *mongo.Client) ([]string, error)
- func (m *MongoOperations) Replace(ctx context.Context, collectionType int, query bson.D, replacement interface{}) (*mongo.UpdateResult, error)
- func (m *MongoOperations) Update(ctx context.Context, collectionType int, query, update bson.D, ...) (*mongo.UpdateResult, error)
- func (m *MongoOperations) UpdateMany(ctx context.Context, collectionType int, query, update bson.D, ...) (*mongo.UpdateResult, error)
- func (m *MongoOperations) WatchEvents(ctx context.Context, client *mongo.Client, collectionType int, ...) (*mongo.ChangeStream, error)
- type MongoOperator
- type ResourceDetails
- type UserDetailResponse
Constants ¶
const ( ChaosInfraCollection = iota ChaosExperimentCollection ChaosExperimentRunsCollection ChaosHubCollection ImageRegistryCollection ServerConfigCollection GitOpsCollection UserCollection ProjectCollection EnvironmentCollection ChaosProbeCollection )
Enum for Database collections
Variables ¶
var ( Client MongoInterface = &MongoClient{} MgoClient *mongo.Client Collections = map[int]string{ ChaosInfraCollection: "chaosInfrastructures", ChaosExperimentCollection: "chaosExperiments", ChaosExperimentRunsCollection: "chaosExperimentRuns", ChaosProbeCollection: "chaosProbes", ChaosHubCollection: "chaosHubs", ImageRegistryCollection: "imageRegistry", ServerConfigCollection: "serverConfig", GitOpsCollection: "gitops", UserCollection: "user", ProjectCollection: "project", EnvironmentCollection: "environment", } DbName = "litmus" ConnectionTimeout = 20 * time.Second )
Functions ¶
func MongoConnection ¶
Types ¶
type Audit ¶
type Audit struct { UpdatedAt int64 `bson:"updated_at"` CreatedAt int64 `bson:"created_at"` CreatedBy UserDetailResponse `bson:"created_by" json:"createdBy"` UpdatedBy UserDetailResponse `bson:"updated_by" json:"updatedBy"` IsRemoved bool `bson:"is_removed"` }
type AuthConfig ¶
type GetCollectionInterface ¶
type GetCollectionInterface interface {
// contains filtered or unexported methods
}
var GetCollectionClient GetCollectionInterface = &GetCollectionStruct{}
type GetCollectionStruct ¶
type GetCollectionStruct struct{}
type MongoClient ¶
type MongoClient struct { Database *mongo.Database ChaosInfraCollection *mongo.Collection ChaosExperimentCollection *mongo.Collection ChaosExperimentRunsCollection *mongo.Collection ChaosHubCollection *mongo.Collection ChaosServerConfigCollection *mongo.Collection ImageRegistryCollection *mongo.Collection ServerConfigCollection *mongo.Collection GitOpsCollection *mongo.Collection UserCollection *mongo.Collection ProjectCollection *mongo.Collection EnvironmentCollection *mongo.Collection ChaosProbeCollection *mongo.Collection }
MongoClient structure contains all the Database collections and the instance of the Database
func (*MongoClient) Initialize ¶
func (m *MongoClient) Initialize(client *mongo.Client) *MongoClient
Initialize initializes database connection
type MongoInterface ¶
type MongoInterface interface { Initialize(client *mongo.Client) *MongoClient // contains filtered or unexported methods }
MongoInterface requires a MongoClient that implements the Initialize method to create the Mongo DB client and a initAllCollection method to initialize all DB Collections
type MongoOperations ¶
type MongoOperations struct {
MongoClient *MongoClient
}
func NewMongoOperations ¶
func NewMongoOperations(mongoClient *MongoClient) *MongoOperations
func (*MongoOperations) Aggregate ¶
func (m *MongoOperations) Aggregate(ctx context.Context, collectionType int, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error)
func (*MongoOperations) CountDocuments ¶
func (m *MongoOperations) CountDocuments(ctx context.Context, collectionType int, query bson.D, opts ...*options.CountOptions) (int64, error)
CountDocuments returns the number of documents in the collection that matches a query
func (*MongoOperations) Create ¶
func (m *MongoOperations) Create(ctx context.Context, collectionType int, document interface{}) error
Create puts a document in the database
func (*MongoOperations) CreateMany ¶
func (m *MongoOperations) CreateMany(ctx context.Context, collectionType int, documents []interface{}) error
CreateMany puts an array of documents in the database
func (*MongoOperations) Delete ¶
func (m *MongoOperations) Delete(ctx context.Context, collectionType int, query bson.D, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
Delete removes a document from the database based on a query
func (*MongoOperations) Get ¶
func (m *MongoOperations) Get(ctx context.Context, collectionType int, query bson.D) (*mongo.SingleResult, error)
Get fetches a document from the database based on a query
func (*MongoOperations) GetAuthConfig ¶
func (m *MongoOperations) GetAuthConfig(ctx context.Context, key string) (*AuthConfig, error)
func (*MongoOperations) GetCollection ¶
func (m *MongoOperations) GetCollection(collectionType int) (*mongo.Collection, error)
GetCollection fetches the correct collection based on the collection type
func (*MongoOperations) List ¶
func (m *MongoOperations) List(ctx context.Context, collectionType int, query bson.D, opts ...*options.FindOptions) (*mongo.Cursor, error)
List fetches a list of documents from the database based on a query
func (*MongoOperations) ListCollection ¶
func (*MongoOperations) ListDataBase ¶
func (*MongoOperations) Replace ¶
func (m *MongoOperations) Replace(ctx context.Context, collectionType int, query bson.D, replacement interface{}) (*mongo.UpdateResult, error)
Replace changes a document with a new one in the database based on a query
func (*MongoOperations) Update ¶
func (m *MongoOperations) Update(ctx context.Context, collectionType int, query, update bson.D, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
Update updates a document in the database based on a query
func (*MongoOperations) UpdateMany ¶
func (m *MongoOperations) UpdateMany(ctx context.Context, collectionType int, query, update bson.D, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
UpdateMany updates multiple documents in the database based on a query
func (*MongoOperations) WatchEvents ¶
func (m *MongoOperations) WatchEvents(ctx context.Context, client *mongo.Client, collectionType int, pipeline mongo.Pipeline, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)
type MongoOperator ¶
type MongoOperator interface { Create(ctx context.Context, collectionType int, document interface{}) error CreateMany(ctx context.Context, collectionType int, documents []interface{}) error Get(ctx context.Context, collectionType int, query bson.D) (*mongo.SingleResult, error) List(ctx context.Context, collectionType int, query bson.D, opts ...*options.FindOptions) (*mongo.Cursor, error) Update(ctx context.Context, collectionType int, query, update bson.D, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) UpdateMany(ctx context.Context, collectionType int, query, update bson.D, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) Replace(ctx context.Context, collectionType int, query bson.D, replacement interface{}) (*mongo.UpdateResult, error) Delete(ctx context.Context, collectionType int, query bson.D, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error) CountDocuments(ctx context.Context, collectionType int, query bson.D, opts ...*options.CountOptions) (int64, error) Aggregate(ctx context.Context, collectionType int, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error) GetCollection(collectionType int) (*mongo.Collection, error) ListCollection(ctx context.Context, mclient *mongo.Client) ([]string, error) ListDataBase(ctx context.Context, mclient *mongo.Client) ([]string, error) WatchEvents(ctx context.Context, client *mongo.Client, collectionType int, pipeline mongo.Pipeline, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error) GetAuthConfig(ctx context.Context, key string) (*AuthConfig, error) }
var ( // Operator contains all the CRUD operations of the mongo database Operator MongoOperator = &MongoOperations{} )
type ResourceDetails ¶
type UserDetailResponse ¶
Directories ¶
Path | Synopsis |
---|---|
Package mocks contains all the mocks for the mongo_operator.go file
|
Package mocks contains all the mocks for the mongo_operator.go file |