/
functions.go
56 lines (48 loc) · 1.86 KB
/
functions.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
47
48
49
50
51
52
53
54
55
56
package mongodb
import (
"context"
pkg "github.com/fonteeBoa/go-log-guardian/pkg/domain"
"go.mongodb.org/mongo-driver/mongo"
)
// InsertBaseLog inserts a base log into the specified MongoDB collection.
//
// Client is the MongoDB client used to connect to the database.
// log is the base log to be inserted.
// Returns an error if the insertion fails.
func InsertBaseLog(Client *mongo.Client, log pkg.LogDetails) error {
collection := getCollection(Client, "baseLogs")
_, err := collection.InsertOne(context.Background(), log)
return err
}
// InsertFunctionLog inserts a function log into the "functionLogs" collection.
//
// Client is a MongoDB client.
// log is the function log to be inserted.
// Returns an error if the insertion fails.
func InsertFunctionLog(Client *mongo.Client, log pkg.LogFunction) error {
collection := getCollection(Client, "functionLogs")
_, err := collection.InsertOne(context.Background(), log)
return err
}
// InsertDatabaseLog inserts a database log into the specified collection.
//
// It takes a mongo.Client object and a pkg.LogDatabase object as parameters.
// It returns an error if the insertion fails.
func InsertDatabaseLog(Client *mongo.Client, log pkg.LogDatabase) error {
collection := getCollection(Client, "databaseLogs")
_, err := collection.InsertOne(context.Background(), log)
return err
}
// InsertRequestLog inserts a request log into the "requestLogs" collection in the MongoDB database.
//
// Parameters:
// - Client: A pointer to a mongo.Client object representing the MongoDB client.
// - log: The request log to be inserted in the collection.
//
// Returns:
// - error: An error, if any, encountered during the insertion process.
func InsertRequestLog(Client *mongo.Client, log pkg.LogRequest) error {
collection := getCollection(Client, "requestLogs")
_, err := collection.InsertOne(context.Background(), log)
return err
}