Browse code

use go-generate to build volume/driver/proxy.go

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2015/06/10 22:46:54
Showing 2 changed files
... ...
@@ -1,20 +1,23 @@
1
+//go:generate pluginrpc-gen -i $GOFILE -o proxy.go -type VolumeDriver -name VolumeDriver
2
+
1 3
 package volumedrivers
2 4
 
3 5
 import "github.com/docker/docker/volume"
4 6
 
5
-type client interface {
6
-	Call(string, interface{}, interface{}) error
7
-}
8
-
9 7
 func NewVolumeDriver(name string, c client) volume.Driver {
10 8
 	proxy := &volumeDriverProxy{c}
11 9
 	return &volumeDriverAdapter{name, proxy}
12 10
 }
13 11
 
14 12
 type VolumeDriver interface {
13
+	// Create a volume with the given name
15 14
 	Create(name string) (err error)
15
+	// Remove the volume with the given name
16 16
 	Remove(name string) (err error)
17
+	// Get the mountpoint of the given volume
17 18
 	Path(name string) (mountpoint string, err error)
19
+	// Mount the given volume and return the mountpoint
18 20
 	Mount(name string) (mountpoint string, err error)
21
+	// Unmount the given volume
19 22
 	Unmount(name string) (err error)
20 23
 }
... ...
@@ -1,74 +1,149 @@
1
+// generated code - DO NOT EDIT
2
+
1 3
 package volumedrivers
2 4
 
3
-import "fmt"
5
+import "errors"
4 6
 
5
-// currently created by hand. generation tool would generate this like:
6
-// $ rpc-gen volume/drivers/api.go VolumeDriver > volume/drivers/proxy.go
7
+type client interface {
8
+	Call(string, interface{}, interface{}) error
9
+}
7 10
 
8
-type volumeDriverRequest struct {
9
-	Name string
11
+type volumeDriverProxy struct {
12
+	client
10 13
 }
11 14
 
12
-type volumeDriverResponse struct {
13
-	Mountpoint string `json:",omitempty"`
14
-	Err        string `json:",omitempty"`
15
+type volumeDriverProxyCreateRequest struct {
16
+	Name string
15 17
 }
16 18
 
17
-type volumeDriverProxy struct {
18
-	c client
19
+type volumeDriverProxyCreateResponse struct {
20
+	Err string
19 21
 }
20 22
 
21
-func (pp *volumeDriverProxy) Create(name string) error {
22
-	args := volumeDriverRequest{name}
23
-	var ret volumeDriverResponse
24
-	err := pp.c.Call("VolumeDriver.Create", args, &ret)
25
-	if err != nil {
26
-		return pp.fmtError(name, err.Error())
23
+func (pp *volumeDriverProxy) Create(name string) (err error) {
24
+	var (
25
+		req volumeDriverProxyCreateRequest
26
+		ret volumeDriverProxyCreateResponse
27
+	)
28
+
29
+	req.Name = name
30
+	if err = pp.Call("VolumeDriver.Create", req, &ret); err != nil {
31
+		return
27 32
 	}
28
-	return pp.fmtError(name, ret.Err)
29
-}
30 33
 
31
-func (pp *volumeDriverProxy) Remove(name string) error {
32
-	args := volumeDriverRequest{name}
33
-	var ret volumeDriverResponse
34
-	err := pp.c.Call("VolumeDriver.Remove", args, &ret)
35
-	if err != nil {
36
-		return pp.fmtError(name, err.Error())
34
+	if ret.Err != "" {
35
+		err = errors.New(ret.Err)
37 36
 	}
38
-	return pp.fmtError(name, ret.Err)
37
+
38
+	return
39
+}
40
+
41
+type volumeDriverProxyRemoveRequest struct {
42
+	Name string
39 43
 }
40 44
 
41
-func (pp *volumeDriverProxy) Path(name string) (string, error) {
42
-	args := volumeDriverRequest{name}
43
-	var ret volumeDriverResponse
44
-	if err := pp.c.Call("VolumeDriver.Path", args, &ret); err != nil {
45
-		return "", pp.fmtError(name, err.Error())
45
+type volumeDriverProxyRemoveResponse struct {
46
+	Err string
47
+}
48
+
49
+func (pp *volumeDriverProxy) Remove(name string) (err error) {
50
+	var (
51
+		req volumeDriverProxyRemoveRequest
52
+		ret volumeDriverProxyRemoveResponse
53
+	)
54
+
55
+	req.Name = name
56
+	if err = pp.Call("VolumeDriver.Remove", req, &ret); err != nil {
57
+		return
46 58
 	}
47
-	return ret.Mountpoint, pp.fmtError(name, ret.Err)
59
+
60
+	if ret.Err != "" {
61
+		err = errors.New(ret.Err)
62
+	}
63
+
64
+	return
48 65
 }
49 66
 
50
-func (pp *volumeDriverProxy) Mount(name string) (string, error) {
51
-	args := volumeDriverRequest{name}
52
-	var ret volumeDriverResponse
53
-	if err := pp.c.Call("VolumeDriver.Mount", args, &ret); err != nil {
54
-		return "", pp.fmtError(name, err.Error())
67
+type volumeDriverProxyPathRequest struct {
68
+	Name string
69
+}
70
+
71
+type volumeDriverProxyPathResponse struct {
72
+	Mountpoint string
73
+	Err        string
74
+}
75
+
76
+func (pp *volumeDriverProxy) Path(name string) (mountpoint string, err error) {
77
+	var (
78
+		req volumeDriverProxyPathRequest
79
+		ret volumeDriverProxyPathResponse
80
+	)
81
+
82
+	req.Name = name
83
+	if err = pp.Call("VolumeDriver.Path", req, &ret); err != nil {
84
+		return
55 85
 	}
56
-	return ret.Mountpoint, pp.fmtError(name, ret.Err)
86
+
87
+	mountpoint = ret.Mountpoint
88
+
89
+	if ret.Err != "" {
90
+		err = errors.New(ret.Err)
91
+	}
92
+
93
+	return
94
+}
95
+
96
+type volumeDriverProxyMountRequest struct {
97
+	Name string
98
+}
99
+
100
+type volumeDriverProxyMountResponse struct {
101
+	Mountpoint string
102
+	Err        string
57 103
 }
58 104
 
59
-func (pp *volumeDriverProxy) Unmount(name string) error {
60
-	args := volumeDriverRequest{name}
61
-	var ret volumeDriverResponse
62
-	err := pp.c.Call("VolumeDriver.Unmount", args, &ret)
63
-	if err != nil {
64
-		return pp.fmtError(name, err.Error())
105
+func (pp *volumeDriverProxy) Mount(name string) (mountpoint string, err error) {
106
+	var (
107
+		req volumeDriverProxyMountRequest
108
+		ret volumeDriverProxyMountResponse
109
+	)
110
+
111
+	req.Name = name
112
+	if err = pp.Call("VolumeDriver.Mount", req, &ret); err != nil {
113
+		return
65 114
 	}
66
-	return pp.fmtError(name, ret.Err)
115
+
116
+	mountpoint = ret.Mountpoint
117
+
118
+	if ret.Err != "" {
119
+		err = errors.New(ret.Err)
120
+	}
121
+
122
+	return
123
+}
124
+
125
+type volumeDriverProxyUnmountRequest struct {
126
+	Name string
67 127
 }
68 128
 
69
-func (pp *volumeDriverProxy) fmtError(name string, err string) error {
70
-	if len(err) == 0 {
71
-		return nil
129
+type volumeDriverProxyUnmountResponse struct {
130
+	Err string
131
+}
132
+
133
+func (pp *volumeDriverProxy) Unmount(name string) (err error) {
134
+	var (
135
+		req volumeDriverProxyUnmountRequest
136
+		ret volumeDriverProxyUnmountResponse
137
+	)
138
+
139
+	req.Name = name
140
+	if err = pp.Call("VolumeDriver.Unmount", req, &ret); err != nil {
141
+		return
72 142
 	}
73
-	return fmt.Errorf("External volume driver request failed for %s: %v", name, err)
143
+
144
+	if ret.Err != "" {
145
+		err = errors.New(ret.Err)
146
+	}
147
+
148
+	return
74 149
 }