@cryptotaxi247 / kubo / commits / 6e9036769

coreapi: Global options for api constructor

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Dec 6, 2018 at 10:47 UTC 6e9036769607b6cd837365312f27810350b6e938
1 file changed +32
core/coreapi/interface/options/global.go new
+32
@@ -0,0 +1,32 @@
1 +package options
2 +
3 +type ApiSettings struct {
4 + Offline bool
5 +}
6 +
7 +type ApiOption func(*ApiSettings) error
8 +
9 +func ApiOptions(opts ...ApiOption) (*ApiSettings, error) {
10 + options := &ApiSettings{
11 + Offline: false,
12 + }
13 +
14 + for _, opt := range opts {
15 + err := opt(options)
16 + if err != nil {
17 + return nil, err
18 + }
19 + }
20 + return options, nil
21 +}
22 +
23 +type apiOpts struct{}
24 +
25 +var Api dagOpts
26 +
27 +func (dagOpts) Offline(offline bool) ApiOption {
28 + return func(settings *ApiSettings) error {
29 + settings.Offline = offline
30 + return nil
31 + }
32 +}