Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
afshin committed Jul 18, 2016
1 parent cd1353f commit e600c76
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
14 changes: 7 additions & 7 deletions client.go
Expand Up @@ -51,8 +51,8 @@ func (c *Client) add(group, name, node, service, version string) error {
}
// Node and service are required. Version is optional.
if node == "" || service == "" {
return newError(errAdd, "failed to add %s node?=%t, type?=%t",
name, node != "", service != "")
format := "add failed for name=\"%s\", node=\"%s\", service=\"%s\""
return newError(errAdd, format, name, node, service)
}
// Associate the node name with its service in the directory.
c.directory[name] = service
Expand All @@ -71,9 +71,9 @@ func (c *Client) add(group, name, node, service, version string) error {
return nil
}

// Blocks until the required services are available to the client.
// Returns true if it had to block and false if it returns immediately.
func (c *Client) block(services ...string) bool {
// Block until the required services are available to the client.
c.additions.Lock()
defer c.additions.Unlock()
// Even though the client may have just checked to see if services exist,
Expand Down Expand Up @@ -106,8 +106,7 @@ func (c *Client) Close() error {
return newError(errLeave, err.Error())
}
if err := c.node.Stop(); err != nil {
c.log.Warn("sleuth: %s %s [%d]",
c.node.Name(), err.Error(), warnClose)
c.log.Warn("sleuth: %s %s [%d]", c.node.Name(), err.Error(), warnClose)
}
return nil
}
Expand Down Expand Up @@ -260,8 +259,9 @@ func newClient(group string, node *gyre.Gyre, out *logger.Logger) *Client {
directory: make(map[string]string),
group: group,
listener: &listener{
new(sync.Mutex),
make(map[string]chan *http.Response)},
Mutex: new(sync.Mutex),
handles: make(map[string]chan *http.Response),
},
log: out,
node: node,
Timeout: time.Millisecond * 500,
Expand Down
4 changes: 2 additions & 2 deletions config.go
Expand Up @@ -63,8 +63,8 @@ func initConfig(config *Config) *Config {
config.LogLevel = "listen"
}
if level, ok := logger.LogLevel[config.LogLevel]; !ok {
logger.MustError("LogLevel=\"%s\" is invalid; using \"%s\" [%d]",
config.LogLevel, "debug", errLogLevel)
format := "LogLevel=\"%s\" is invalid; using \"%s\" [%d]"
logger.MustError(format, config.LogLevel, "debug", errLogLevel)
config.LogLevel = "debug"
config.logLevel = logger.Debug
} else {
Expand Down
11 changes: 6 additions & 5 deletions request.go
Expand Up @@ -21,20 +21,21 @@ type request struct {
}

func reqMarshal(group, dest, handle string, in *http.Request) ([]byte, error) {
out := &request{}
out := &request{
Destination: dest,
Handle: handle,
Header: map[string][]string(in.Header),
Method: in.Method,
}
if in.Body != nil {
if body, err := ioutil.ReadAll(in.Body); err == nil {
out.Body = body
}
}
out.Header = map[string][]string(in.Header)
out.Method = in.Method
// Scheme and Host are used by sleuth for routing, but should not be sent.
in.URL.Scheme = ""
in.URL.Host = ""
out.URL = in.URL.String()
out.Destination = dest
out.Handle = handle
marshalled, err := json.Marshal(out)
if err != nil {
return nil, newError(errReqMarshal, err.Error())
Expand Down
5 changes: 4 additions & 1 deletion workers.go
Expand Up @@ -59,5 +59,8 @@ func (w *workers) remove(name string) (int, *peer) {
}

func newWorkers() *workers {
return &workers{Mutex: new(sync.Mutex), list: make([]*peer, 0)}
return &workers{
Mutex: new(sync.Mutex),
list: make([]*peer, 0),
}
}
3 changes: 2 additions & 1 deletion writer.go
Expand Up @@ -47,7 +47,8 @@ func newWriter(node whisperer, dest *destination) *writer {
group: dest.group,
output: &response{
Handle: dest.handle,
Header: http.Header(make(map[string][]string))},
Header: http.Header(make(map[string][]string)),
},
peer: dest.node,
whisperer: node,
}
Expand Down

0 comments on commit e600c76

Please sign in to comment.