-
Notifications
You must be signed in to change notification settings - Fork 0
/
setters.go
61 lines (55 loc) · 1.57 KB
/
setters.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
50
51
52
53
54
55
56
57
58
59
60
61
package datamesh
import (
"github.com/openziti-incubator/cf"
"github.com/openziti/dilithium"
"github.com/openziti/foundation/transport"
"github.com/pkg/errors"
"reflect"
)
func TransportAddressSetter(v interface{}, f reflect.Value) error {
if vt, ok := v.(string); ok {
addr, err := transport.ParseAddress(vt)
if err != nil {
return errors.Wrapf(err, "error parsing '%s'", vt)
}
if f.Kind() == reflect.Ptr {
f.Elem().Set(reflect.ValueOf(addr))
} else {
f.Set(reflect.ValueOf(addr))
}
return nil
}
return errors.Errorf("got '%s', expected '%s'", reflect.TypeOf(v), f.Type())
}
func CircuitSetter(v interface{}, f reflect.Value) error {
if vt, ok := v.(string); ok {
if f.Kind() == reflect.Ptr {
f.Elem().SetString(vt)
} else {
f.SetString(vt)
}
return nil
}
return errors.Errorf("got [%s], expected [%s]", reflect.TypeOf(v), f.Type())
}
func WestworldProfileFlexibleSetter(v interface{}, opt *cf.Options) (interface{}, error) {
wp := dilithium.NewBaselineWestworldProfile()
if err := cf.Bind(wp, v.(map[string]interface{}), opt); err != nil {
return nil, err
}
return wp, nil
}
func ProxyListenerFactorySetter(v interface{}, opt *cf.Options) (interface{}, error) {
pxlf := &ProxyListenerFactory{}
if err := cf.Bind(pxlf, v.(map[string]interface{}), opt); err != nil {
return nil, err
}
return pxlf, nil
}
func ProxyTerminatorFactorySetter(v interface{}, opt *cf.Options) (interface{}, error) {
pxtf := &ProxyTerminatorFactory{}
if err := cf.Bind(pxtf, v.(map[string]interface{}), opt); err != nil {
return nil, err
}
return pxtf, nil
}