/
client.go
149 lines (137 loc) · 3.74 KB
/
client.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Generated
package offers
import (
"net/rpc"
"github.com/willfaught/company/prototype/company/offer"
)
var _ Interface = Client{}
// Client is the RPC client.
type Client struct {
// Client is the wrapped RPC client.
*rpc.Client
// Configuration is the configuration.
Configuration Configuration
// Context is the call context.
Context Context
// Name is the receiver name.
Name string
}
// MustNewClient calls NewClient and panics if there is an error.
func MustNewClient(c Configuration, address string) Client {
var client, err = NewClient(c, address)
if err != nil {
panic(err)
}
return client
}
// NewClient makes a Client that uses h and dials address.
func NewClient(c Configuration, address string) (Client, error) {
var client, err = rpc.Dial("tcp", address)
if err != nil {
return Client{}, err
}
return Client{Client: client, Configuration: c, Name: "Marketing"}, nil // Default receiver name is "Marketing".
}
// Delete deletes m.
func (c Client) Delete(m offer.Offer) (offer.Offer, error) {
m.Interface = nil // Avoid encoding the Service or Client
var argument = struct {
Arguments struct { // Method arguments
M offer.Offer // m
}
Context Context // Call context
}{
Arguments: struct { // Method arguments
M offer.Offer // m
}{
M: m, // m
},
Context: c.Context, // Call context
}
var result struct { // Method result
Offer offer.Offer // Only one non-error result
}
c.Configuration.OnCall("Delete", argument.Context, argument.Arguments) // Called because Configuration implements it
var err = c.Client.Call(c.Name+".Delete", argument, &result)
c.Configuration.OnReturn("Delete", argument.Context, result, err) // Called because Configuration implements it
result.Offer.Interface = c // Enable method calls like m.Delete(). See offer.Offer.Delete.
return result.Offer, err
}
// ForContext uses c.
func (c Client) ForContext(co Context) Interface { // Generated because ForContext(Context) Interface was found in the Service interface.
return Client{Client: c.Client, Configuration: c.Configuration, Context: co, Name: c.Name}
}
// Get gets the Offer for id.
func (c Client) Get(id string) (offer.Offer, error) {
var argument = struct {
Arguments struct {
Id string // id
}
Context Context
}{
Arguments: struct {
Id string // id
}{
Id: id, // id
},
Context: c.Context,
}
var result struct {
Offer offer.Offer
}
c.Configuration.OnCall("Get", argument.Context, argument.Arguments)
var err = c.Client.Call(c.Name+".Get", argument, &result)
c.Configuration.OnReturn("Get", argument.Context, result, err)
result.Offer.Interface = c
return result.Offer, err
}
// New creates m.
func (c Client) New(m offer.Offer) (offer.Offer, error) {
m.Interface = nil
var argument = struct {
Arguments struct {
M offer.Offer
}
Context Context
}{
Arguments: struct {
M offer.Offer
}{
M: m,
},
Context: c.Context,
}
var result struct {
Offer offer.Offer
}
c.Configuration.OnCall("New", argument.Context, argument.Arguments)
var err = c.Client.Call(c.Name+".New", argument, &result)
c.Configuration.OnReturn("New", argument.Context, result, err)
result.Offer.Interface = c
return result.Offer, err
}
// Set updates m.
func (c Client) Set(m offer.Offer) (offer.Offer, error) {
m.Interface = nil
var argument = struct {
Arguments struct {
M offer.Offer
}
Context Context
}{
Arguments: struct {
M offer.Offer
}{
M: m,
},
Context: c.Context,
}
var result struct {
Offer offer.Offer
}
c.Configuration.OnCall("Set", argument.Context, argument.Arguments)
var err = c.Client.Call(c.Name+".Set", argument, &result)
c.Configuration.OnReturn("Set", argument.Context, result, err)
result.Offer.Interface = c
return result.Offer, err
}