forked from rexray/rexray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libstorage_go17.go
49 lines (38 loc) · 1.23 KB
/
libstorage_go17.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
// +build go1.7
package libstorage
import (
"context"
gofig "github.com/akutz/gofig/types"
apictx "github.com/rexray/rexray/libstorage/api/context"
"github.com/rexray/rexray/libstorage/api/server"
"github.com/rexray/rexray/libstorage/api/types"
"github.com/rexray/rexray/libstorage/api/utils"
"github.com/rexray/rexray/libstorage/client"
)
// New starts an embedded libStorage server and returns both the server
// instnace as well as a client connected to said instnace.
//
// While a new server may be launched, it's still up to the caller to provide
// a config instance with the correct properties to specify service
// information for a libStorage server.
func New(
goCtx context.Context,
config gofig.Config) (types.Client, types.Server, <-chan error, error) {
ctx := apictx.New(goCtx)
if _, ok := apictx.PathConfig(ctx); !ok {
pathConfig := utils.NewPathConfig()
ctx = ctx.WithValue(apictx.PathConfigKey, pathConfig)
}
s, errs, err := server.Serve(ctx, config)
if err != nil {
return nil, nil, nil, err
}
if h := config.GetString(types.ConfigHost); h == "" {
config.Set(types.ConfigHost, s.Addrs()[0])
}
c, err := client.New(ctx, config)
if err != nil {
return nil, nil, nil, err
}
return c, s, errs, nil
}