Skip to content

Commit e600c76

Browse files
committed
clean up
1 parent cd1353f commit e600c76

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func (c *Client) add(group, name, node, service, version string) error {
5151
}
5252
// Node and service are required. Version is optional.
5353
if node == "" || service == "" {
54-
return newError(errAdd, "failed to add %s node?=%t, type?=%t",
55-
name, node != "", service != "")
54+
format := "add failed for name=\"%s\", node=\"%s\", service=\"%s\""
55+
return newError(errAdd, format, name, node, service)
5656
}
5757
// Associate the node name with its service in the directory.
5858
c.directory[name] = service
@@ -71,9 +71,9 @@ func (c *Client) add(group, name, node, service, version string) error {
7171
return nil
7272
}
7373

74+
// Blocks until the required services are available to the client.
7475
// Returns true if it had to block and false if it returns immediately.
7576
func (c *Client) block(services ...string) bool {
76-
// Block until the required services are available to the client.
7777
c.additions.Lock()
7878
defer c.additions.Unlock()
7979
// Even though the client may have just checked to see if services exist,
@@ -106,8 +106,7 @@ func (c *Client) Close() error {
106106
return newError(errLeave, err.Error())
107107
}
108108
if err := c.node.Stop(); err != nil {
109-
c.log.Warn("sleuth: %s %s [%d]",
110-
c.node.Name(), err.Error(), warnClose)
109+
c.log.Warn("sleuth: %s %s [%d]", c.node.Name(), err.Error(), warnClose)
111110
}
112111
return nil
113112
}
@@ -260,8 +259,9 @@ func newClient(group string, node *gyre.Gyre, out *logger.Logger) *Client {
260259
directory: make(map[string]string),
261260
group: group,
262261
listener: &listener{
263-
new(sync.Mutex),
264-
make(map[string]chan *http.Response)},
262+
Mutex: new(sync.Mutex),
263+
handles: make(map[string]chan *http.Response),
264+
},
265265
log: out,
266266
node: node,
267267
Timeout: time.Millisecond * 500,

config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ func initConfig(config *Config) *Config {
6363
config.LogLevel = "listen"
6464
}
6565
if level, ok := logger.LogLevel[config.LogLevel]; !ok {
66-
logger.MustError("LogLevel=\"%s\" is invalid; using \"%s\" [%d]",
67-
config.LogLevel, "debug", errLogLevel)
66+
format := "LogLevel=\"%s\" is invalid; using \"%s\" [%d]"
67+
logger.MustError(format, config.LogLevel, "debug", errLogLevel)
6868
config.LogLevel = "debug"
6969
config.logLevel = logger.Debug
7070
} else {

request.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,21 @@ type request struct {
2121
}
2222

2323
func reqMarshal(group, dest, handle string, in *http.Request) ([]byte, error) {
24-
out := &request{}
24+
out := &request{
25+
Destination: dest,
26+
Handle: handle,
27+
Header: map[string][]string(in.Header),
28+
Method: in.Method,
29+
}
2530
if in.Body != nil {
2631
if body, err := ioutil.ReadAll(in.Body); err == nil {
2732
out.Body = body
2833
}
2934
}
30-
out.Header = map[string][]string(in.Header)
31-
out.Method = in.Method
3235
// Scheme and Host are used by sleuth for routing, but should not be sent.
3336
in.URL.Scheme = ""
3437
in.URL.Host = ""
3538
out.URL = in.URL.String()
36-
out.Destination = dest
37-
out.Handle = handle
3839
marshalled, err := json.Marshal(out)
3940
if err != nil {
4041
return nil, newError(errReqMarshal, err.Error())

workers.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,8 @@ func (w *workers) remove(name string) (int, *peer) {
5959
}
6060

6161
func newWorkers() *workers {
62-
return &workers{Mutex: new(sync.Mutex), list: make([]*peer, 0)}
62+
return &workers{
63+
Mutex: new(sync.Mutex),
64+
list: make([]*peer, 0),
65+
}
6366
}

writer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ func newWriter(node whisperer, dest *destination) *writer {
4747
group: dest.group,
4848
output: &response{
4949
Handle: dest.handle,
50-
Header: http.Header(make(map[string][]string))},
50+
Header: http.Header(make(map[string][]string)),
51+
},
5152
peer: dest.node,
5253
whisperer: node,
5354
}

0 commit comments

Comments
 (0)