@cryptotaxi247 / kubo / commits / f24ab99f7

coreapi: Global options for api constructor

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com> This commit was moved from ipfs/interface-go-ipfs-core@84509e38781da3257c7a82d09483b4c7d9188a10 This commit was moved from ipfs/boxo@3d132ddab18ee64dc731918e08fd4548d1b335dc

Łukasz Magiera committed Dec 6, 2018 at 10:47 UTC f24ab99f72cfd21bd1db9c781da52ea0e9ca0945
1 file changed +32
core/coreiface/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 +}