go.temporal.io/server/common/dynamicconfig/setting.go

50 LOC · 0 covered · 50 uncovered · 0 ranges · 0 concepts · 0 introducers · 0 tests

1 //go:generate go run ../../cmd/tools/gendynamicconfig
2
3 package dynamicconfig
4
5 type (
6 // Precedence is an enum for the search order precedence of a dynamic config setting.
7 // E.g., use the global value, check namespace then global, check task queue then
8 // namespace then global, etc.
9 Precedence int
10
11 // setting is one dynamic config setting. setting should not be used or created directly,
12 // but use one of the generated constructors for instantiated Setting types in
13 // setting_gen.go, e.g. NewNamespaceBoolSetting.
14 // T is the data type of the setting. P is a go type representing the precedence, which is
15 // just used to make the types more unique.
16 setting[T any, P any] struct {
17 key Key // string value of key. case-insensitive.
18 def T // default value
19 convert func(any) (T, error) // converter function
20 description string // documentation
21 }
22
23 constrainedDefaultSetting[T any, P any] struct {
24 key Key // string value of key. case-insensitive.
25 cdef []TypedConstrainedValue[T] // default values
26 convert func(any) (T, error) // converter function
27 description string // documentation
28 }
29
30 // GenericSetting is an interface that all instances of Setting implement (by generated
31 // code in setting_gen.go). It can be used to refer to settings of any type and deal with
32 // them generically..
33 GenericSetting interface {
34 Key() Key
35 Precedence() Precedence
36 Validate(v any) error
37
38 // for internal use:
39 dispatchUpdate(*Collection, any, []ConstrainedValue)
40 }
41
42 // GenericParseHook is an interface that may be implemented by a setting type or a field
43 // contained inside a struct setting type.
44 // It should be implemented with a non-pointer receiver that will be ignored, and return
45 // the parsed value and any parse error.
46 // Type "S" is usually "string", and "T" must be the same as the receiver type.
47 GenericParseHook[S, T any] interface {
48 DynamicConfigParseHook(S) (T, error)
49 }
50 )