-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmap.go
44 lines (36 loc) · 829 Bytes
/
map.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
package compress
import (
"github.com/alexfalkowski/go-service/compress/none"
"github.com/alexfalkowski/go-service/compress/s2"
"github.com/alexfalkowski/go-service/compress/snappy"
"github.com/alexfalkowski/go-service/compress/zstd"
)
type configs map[string]Compressor
// Map of compressor.
type Map struct {
configs configs
}
// NewMap for compressor.
func NewMap() *Map {
f := &Map{
configs: configs{
"zstd": zstd.NewCompressor(),
"s2": s2.NewCompressor(),
"snappy": snappy.NewCompressor(),
"none": none.NewCompressor(),
},
}
return f
}
// Register kind and compressor.
func (f *Map) Register(kind string, c Compressor) {
f.configs[kind] = c
}
// Get from kind.
func (f *Map) Get(kind string) Compressor {
c, ok := f.configs[kind]
if !ok {
return f.configs["none"]
}
return c
}