-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
42 lines (33 loc) · 904 Bytes
/
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
package datadog
import (
"github.com/americanas-go/config"
grpctrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/google.golang.org/grpc"
)
// Options datadog plugin for grpc server options.
type Options struct {
Enabled bool
traceOptions []grpctrace.Option
}
// NewOptions returns options from config file or environment vars.
func NewOptions(traceOptions ...grpctrace.Option) (*Options, error) {
o := &Options{
traceOptions: traceOptions,
}
err := config.UnmarshalWithPath(root, o)
if err != nil {
return nil, err
}
return o, nil
}
// NewOptionsWithPath unmarshals options based a given key path.
func NewOptionsWithPath(path string, traceOptions ...grpctrace.Option) (opts *Options, err error) {
opts, err = NewOptions(traceOptions...)
if err != nil {
return nil, err
}
err = config.UnmarshalWithPath(path, opts)
if err != nil {
return nil, err
}
return opts, nil
}