8
8
9
9
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
10
10
"github.com/darkweak/souin/configurationtypes"
11
- "go.uber.org/zap "
11
+ "github.com/darkweak/storages/core "
12
12
)
13
13
14
14
// DefaultCache the struct
@@ -38,6 +38,8 @@ type DefaultCache struct {
38
38
Redis configurationtypes.CacheProvider `json:"redis"`
39
39
// Etcd provider configuration.
40
40
Etcd configurationtypes.CacheProvider `json:"etcd"`
41
+ // Nats provider configuration.
42
+ Nats configurationtypes.CacheProvider `json:"nats"`
41
43
// NutsDB provider configuration.
42
44
Nuts configurationtypes.CacheProvider `json:"nuts"`
43
45
// Otter provider configuration.
@@ -52,6 +54,8 @@ type DefaultCache struct {
52
54
TTL configurationtypes.Duration `json:"ttl"`
53
55
// Stale time to live.
54
56
Stale configurationtypes.Duration `json:"stale"`
57
+ // Disable the coalescing system.
58
+ DisableCoalescing bool `json:"disable_coalescing"`
55
59
}
56
60
57
61
// GetAllowedHTTPVerbs returns the allowed verbs to cache
@@ -99,6 +103,11 @@ func (d *DefaultCache) GetMode() string {
99
103
return d .Mode
100
104
}
101
105
106
+ // GetNats returns nuts configuration
107
+ func (d * DefaultCache ) GetNats () configurationtypes.CacheProvider {
108
+ return d .Nats
109
+ }
110
+
102
111
// GetNuts returns nuts configuration
103
112
func (d * DefaultCache ) GetNuts () configurationtypes.CacheProvider {
104
113
return d .Nuts
@@ -154,6 +163,11 @@ func (d *DefaultCache) GetMaxBodyBytes() uint64 {
154
163
return d .MaxBodyBytes
155
164
}
156
165
166
+ // IsCoalescingDisable returns if the coalescing is disabled
167
+ func (d * DefaultCache ) IsCoalescingDisable () bool {
168
+ return d .DisableCoalescing
169
+ }
170
+
157
171
// Configuration holder
158
172
type Configuration struct {
159
173
// Default cache to fallback on when none are redefined.
@@ -168,7 +182,7 @@ type Configuration struct {
168
182
LogLevel string
169
183
// SurrogateKeys contains the surrogate keys to use with a predefined mapping
170
184
SurrogateKeys map [string ]configurationtypes.SurrogateKeys
171
- logger * zap .Logger
185
+ logger core .Logger
172
186
}
173
187
174
188
// GetUrls get the urls list in the configuration
@@ -197,12 +211,12 @@ func (c *Configuration) GetLogLevel() string {
197
211
}
198
212
199
213
// GetLogger get the logger
200
- func (c * Configuration ) GetLogger () * zap .Logger {
214
+ func (c * Configuration ) GetLogger () core .Logger {
201
215
return c .logger
202
216
}
203
217
204
218
// SetLogger set the logger
205
- func (c * Configuration ) SetLogger (l * zap .Logger ) {
219
+ func (c * Configuration ) SetLogger (l core .Logger ) {
206
220
c .logger = l
207
221
}
208
222
@@ -269,19 +283,25 @@ func parseBadgerConfiguration(c map[string]interface{}) map[string]interface{} {
269
283
func parseRedisConfiguration (c map [string ]interface {}) map [string ]interface {} {
270
284
for k , v := range c {
271
285
switch k {
272
- case "InitAddress" :
286
+ case "Addrs" , " InitAddress" :
273
287
if s , ok := v .(string ); ok {
274
288
c [k ] = []string {s }
275
289
} else {
276
290
c [k ] = v
277
291
}
278
- case "Username" , "Password" , "ClientName" , "ClientSetInfo" , "ClientTrackingOptions" :
292
+ case "Username" , "Password" , "ClientName" , "ClientSetInfo" , "ClientTrackingOptions" , "SentinelUsername" , "SentinelPassword" , "MasterName" , "IdentitySuffix" :
279
293
c [k ] = v
280
294
case "SendToReplicas" , "ShuffleInit" , "ClientNoTouch" , "DisableRetry" , "DisableCache" , "AlwaysPipelining" , "AlwaysRESP2" , "ForceSingleClient" , "ReplicaOnly" , "ClientNoEvict" :
281
295
c [k ] = true
282
- case "SelectDB" , "CacheSizeEachConn" , "RingScaleEachConn" , "ReadBufferEachConn" , "WriteBufferEachConn" , "BlockingPoolSize" , "PipelineMultiplex" :
283
- c [k ], _ = strconv .Atoi (v .(string ))
284
- case "ConnWriteTimeout" , "MaxFlushDelay" :
296
+ case "SelectDB" , "CacheSizeEachConn" , "RingScaleEachConn" , "ReadBufferEachConn" , "WriteBufferEachConn" , "BlockingPoolSize" , "PipelineMultiplex" , "DB" , "Protocol" , "MaxRetries" , "PoolSize" , "MinIdleConns" , "MaxIdleConns" , "MaxActiveConns" , "MaxRedirects" :
297
+ if v == false {
298
+ c [k ] = 0
299
+ } else if v == true {
300
+ c [k ] = 1
301
+ } else {
302
+ c [k ], _ = strconv .Atoi (v .(string ))
303
+ }
304
+ case "ConnWriteTimeout" , "MaxFlushDelay" , "MinRetryBackoff" , "MaxRetryBackoff" , "DialTimeout" , "ReadTimeout" , "WriteTimeout" , "PoolTimeout" , "ConnMaxIdleTime" , "ConnMaxLifetime" :
285
305
c [k ], _ = time .ParseDuration (v .(string ))
286
306
}
287
307
}
@@ -350,7 +370,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
350
370
}
351
371
cfg .API = apiConfiguration
352
372
case "badger" :
353
- provider := configurationtypes.CacheProvider {}
373
+ provider := configurationtypes.CacheProvider {Found : true }
354
374
for nesting := h .Nesting (); h .NextBlock (nesting ); {
355
375
directive := h .Val ()
356
376
switch directive {
@@ -447,7 +467,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
447
467
}
448
468
case "etcd" :
449
469
cfg .DefaultCache .Distributed = true
450
- provider := configurationtypes.CacheProvider {}
470
+ provider := configurationtypes.CacheProvider {Found : true }
451
471
for nesting := h .Nesting (); h .NextBlock (nesting ); {
452
472
directive := h .Val ()
453
473
switch directive {
@@ -497,8 +517,23 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
497
517
return h .Errf ("mode must contains only one arg: %s given" , args )
498
518
}
499
519
cfg .DefaultCache .Mode = args [0 ]
520
+ case "nats" :
521
+ provider := configurationtypes.CacheProvider {Found : true }
522
+ for nesting := h .Nesting (); h .NextBlock (nesting ); {
523
+ directive := h .Val ()
524
+ switch directive {
525
+ case "url" :
526
+ urlArgs := h .RemainingArgs ()
527
+ provider .URL = urlArgs [0 ]
528
+ case "configuration" :
529
+ provider .Configuration = parseCaddyfileRecursively (h )
530
+ default :
531
+ return h .Errf ("unsupported nats directive: %s" , directive )
532
+ }
533
+ }
534
+ cfg .DefaultCache .Nuts = provider
500
535
case "nuts" :
501
- provider := configurationtypes.CacheProvider {}
536
+ provider := configurationtypes.CacheProvider {Found : true }
502
537
for nesting := h .Nesting (); h .NextBlock (nesting ); {
503
538
directive := h .Val ()
504
539
switch directive {
@@ -516,7 +551,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
516
551
}
517
552
cfg .DefaultCache .Nuts = provider
518
553
case "otter" :
519
- provider := configurationtypes.CacheProvider {}
554
+ provider := configurationtypes.CacheProvider {Found : true }
520
555
for nesting := h .Nesting (); h .NextBlock (nesting ); {
521
556
directive := h .Val ()
522
557
switch directive {
@@ -529,7 +564,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
529
564
cfg .DefaultCache .Otter = provider
530
565
case "olric" :
531
566
cfg .DefaultCache .Distributed = true
532
- provider := configurationtypes.CacheProvider {}
567
+ provider := configurationtypes.CacheProvider {Found : true }
533
568
for nesting := h .Nesting (); h .NextBlock (nesting ); {
534
569
directive := h .Val ()
535
570
switch directive {
@@ -548,7 +583,7 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
548
583
cfg .DefaultCache .Olric = provider
549
584
case "redis" :
550
585
cfg .DefaultCache .Distributed = true
551
- provider := configurationtypes.CacheProvider {}
586
+ provider := configurationtypes.CacheProvider {Found : true }
552
587
for nesting := h .Nesting (); h .NextBlock (nesting ); {
553
588
directive := h .Val ()
554
589
switch directive {
@@ -615,6 +650,8 @@ func parseConfiguration(cfg *Configuration, h *caddyfile.Dispenser, isGlobal boo
615
650
if err == nil {
616
651
cfg .DefaultCache .TTL .Duration = ttl
617
652
}
653
+ case "disable_coalescing" :
654
+ cfg .DefaultCache .DisableCoalescing = true
618
655
default :
619
656
return h .Errf ("unsupported root directive: %s" , rootOption )
620
657
}
0 commit comments