/
mo_db_config.go
104 lines (85 loc) · 3.2 KB
/
mo_db_config.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package mongostorage
// GetDefaultMongoStorageConfig returns a MongoStorageConfig with default values.
func GetDefaultMongoStorageConfig() MongoStorageConfig {
cfg := MongoStorageConfig{
// Default MongoDB connection URI
MongoURI: DefaultMongoURI,
// Default MongoDB database name
MongoDatabaseName: DefaultMongoDatabaseName,
// Default MongoDB collection name
MongoCollection: DefaultMongoCollection,
// Default MongoDB timeout (in seconds) for connecting to the server
MongoTimeout: DefaultMongoTimeout,
// Default size of the delete queue (number of delete requests buffered before blocking)
DelQueue: DefaultDelQueue,
// Default number of delete worker goroutines
DelWorker: DefaultDelWorker,
// Default number of MessageIDs a DeleteWorker will cache before deleting to batch into one process
DelBatch: DefaultDeleteBatchSize,
// Default size of the insert queue (number of insertion requests buffered before blocking)
InsQueue: DefaultInsQueue,
// Default number of insert worker goroutines
InsWorker: DefaultInsWorker,
// Default number of Articles an InsertWorker will cache before inserting to batch into one process
InsBatch: DefaultInsertBatchSize,
// Default size of the read queue (number of read requests buffered before blocking)
GetQueue: DefaultGetQueue,
// Default number of reader worker goroutines
GetWorker: DefaultGetWorker,
// The default time in milliseconds for flushing batched operations to MongoDB.
// If the batch is not full, it will flush after the specified time.
// Setting it too low may waste CPU cycles, and if you want instant processing, keep the batch sizes as 1 (default).
FlushTimer: DefaultFlushTimer,
// Default test flag for performing a test after an article insertion
TestAfterInsert: false, // You can change this to true if you want to perform a test after an article insertion.
}
return cfg
} // end func GetDefaultMongoStorageConfig
// SetDefaultsIfZero takes a pointer to a MongoStorageConfig and sets integer-typed fields to their default values
// if their current value is less than or equal to zero. It also sets default values for empty strings.
// This function is useful for ensuring that all the fields in the MongoStorageConfig have valid values.
func SetDefaultsIfZero(cfg *MongoStorageConfig) {
if cfg == nil {
return
}
if cfg.MongoURI == "" {
cfg.MongoURI = DefaultMongoURI
}
if cfg.MongoDatabaseName == "" {
cfg.MongoDatabaseName = DefaultMongoDatabaseName
}
if cfg.MongoCollection == "" {
cfg.MongoCollection = DefaultMongoCollection
}
if cfg.MongoTimeout <= 0 {
cfg.MongoTimeout = DefaultMongoTimeout
}
if cfg.DelQueue <= 0 {
cfg.DelQueue = DefaultDelQueue
}
if cfg.DelWorker <= 0 {
cfg.DelWorker = DefaultDelWorker
}
if cfg.DelBatch <= 0 {
cfg.DelBatch = DefaultDeleteBatchSize
}
if cfg.InsQueue <= 0 {
cfg.InsQueue = DefaultInsQueue
}
if cfg.InsWorker <= 0 {
cfg.InsWorker = DefaultInsWorker
}
if cfg.InsBatch <= 0 {
cfg.InsBatch = DefaultInsertBatchSize
}
if cfg.GetQueue <= 0 {
cfg.GetQueue = DefaultGetQueue
}
if cfg.GetWorker <= 0 {
cfg.GetWorker = DefaultGetWorker
}
if cfg.FlushTimer <= 0 {
cfg.FlushTimer = 1000
}
} // end func SetDefaultsIfZero
// EOF mo_db_config.go