-
Notifications
You must be signed in to change notification settings - Fork 13
/
options.go
45 lines (36 loc) · 1.11 KB
/
options.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
// Copyright 2023 Synnax Labs, Inc.
//
// Use of this software is governed by the Business Source License included in the file
// licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with the Business Source
// License, use of this software will be governed by the Apache License, Version 2.0,
// included in the file licenses/APL.txt.
package gorp
import (
"github.com/synnaxlabs/x/binary"
"github.com/synnaxlabs/x/override"
)
type Option func(o *options)
// WithCodec sets the encoder (and decoder) used to serialize entries. It's
// important to note that reading data encoded in a different format may cause
// undefined behavior.
func WithCodec(ecd binary.Codec) Option {
return func(opts *options) { opts.Codec = ecd }
}
type options struct {
binary.Codec
}
var _ Tools = options{}
var defaultOptions = options{Codec: &binary.MsgPackCodec{}}
func newOptions(opts []Option) options {
o := defaultOptions
for _, opt := range opts {
opt(&o)
}
return overrideOptions(o)
}
func overrideOptions(o options) options {
o.Codec = override.Nil(defaultOptions.Codec, o.Codec)
return o
}