-
Notifications
You must be signed in to change notification settings - Fork 416
/
op_cache.go
49 lines (41 loc) · 1.49 KB
/
op_cache.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2023 Datadog, Inc.
package namingschema
import "fmt"
type cacheOutboundOp struct {
cfg *config
system string
}
// NewCacheOutboundOp creates a new naming schema for outbound operations from caching systems.
// The V0 implementation defaults to the v1 and is meant to be overwritten if needed, since (generally) it does not
// follow any pattern among cache integrations.
func NewCacheOutboundOp(system string, opts ...Option) *Schema {
cfg := &config{}
for _, opt := range opts {
opt(cfg)
}
return New(&cacheOutboundOp{cfg: cfg, system: system})
}
func (c *cacheOutboundOp) V0() string {
if v, ok := c.cfg.versionOverrides[SchemaV0]; ok {
return v
}
return c.V1()
}
func (c *cacheOutboundOp) V1() string {
if v, ok := c.cfg.versionOverrides[SchemaV1]; ok {
return v
}
return fmt.Sprintf("%s.command", c.system)
}
// NewMemcachedOutboundOp creates a new schema for Memcached (cache) outbound operations.
func NewMemcachedOutboundOp(opts ...Option) *Schema {
newOpts := append([]Option{WithVersionOverride(SchemaV0, "memcached.query")}, opts...)
return NewCacheOutboundOp("memcached", newOpts...)
}
// NewRedisOutboundOp creates a new schema for Redis (cache) outbound operations.
func NewRedisOutboundOp(opts ...Option) *Schema {
return NewCacheOutboundOp("redis", opts...)
}