Skip to content

Commit 75df41a

Browse files
committed
move any struct that is used by more than one file to its own file, rename marshallers
1 parent 4c0d498 commit 75df41a

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (c *Client) listen(handle string, listener chan *http.Response) {
192192
}
193193

194194
func (c *Client) receive(payload []byte) error {
195-
handle, res, err := unmarshalRes(payload)
195+
handle, res, err := resUnmarshal(payload)
196196
if err != nil {
197197
return err.(*Error).escalate(errRECV)
198198
}

destination.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2016 Afshin Darian. All rights reserved.
2+
// Use of this source code is governed by The MIT License
3+
// that can be found in the LICENSE file.
4+
5+
package sleuth
6+
7+
// destination describes the group, node, and specific handle of a message.
8+
type destination struct {
9+
group string
10+
handle string
11+
node string
12+
}

request.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ import (
1111
"net/http"
1212
)
1313

14-
type destination struct {
15-
group string
16-
handle string
17-
node string
18-
}
19-
2014
type request struct {
2115
Body []byte `json:"body,omitempty"`
2216
Destination string `json:"destination"`

response.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ type body struct {
2424

2525
func (*body) Close() error { return nil }
2626

27-
func marshalRes(group string, res *response) []byte {
27+
func resMarshal(group string, res *response) []byte {
2828
// This will never fail to marshal, so error can be ignored.
2929
marshalled, _ := json.Marshal(res)
3030
return append([]byte(group+recv), zip(marshalled)...)
3131
}
3232

33-
func unmarshalRes(payload []byte) (string, *http.Response, error) {
33+
func resUnmarshal(payload []byte) (string, *http.Response, error) {
3434
var handle string
3535
var res *http.Response
3636
unzipped, err := unzip(payload)

sleuth_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestClientReceiveBadHandle(t *testing.T) {
136136
log, _ := logger.New(logger.Silent)
137137
c := newClient(GROUP, nil, log)
138138
res := &response{Handle: "1"}
139-
err := c.receive(marshalRes(GROUP, res)[len(GROUP)+len(recv):])
139+
err := c.receive(resMarshal(GROUP, res)[len(GROUP)+len(recv):])
140140
if err == nil {
141141
t.Errorf("expected client receive to fail on bad handle")
142142
return
@@ -230,9 +230,9 @@ func TestRequestUnmarshalBadJSON(t *testing.T) {
230230

231231
func TestResponseUnmarshalBadJSON(t *testing.T) {
232232
payload := zip([]byte("{bad json}"))
233-
_, _, err := unmarshalRes(payload)
233+
_, _, err := resUnmarshal(payload)
234234
if err == nil {
235-
t.Errorf("expected unmarshalRes to fail on bad json")
235+
t.Errorf("expected resUnmarshal to fail on bad json")
236236
return
237237
}
238238
testCodes(t, err, []int{errResUnmarshalJSON})

writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (w *writer) Write(data []byte) (int, error) {
3131
header.Add("Content-Type", http.DetectContentType(data))
3232
}
3333
w.output.Body = data
34-
payload := marshalRes(w.group, w.output)
34+
payload := resMarshal(w.group, w.output)
3535
if err := w.whisperer.Whisper(w.peer, payload); err != nil {
3636
return 0, newError(errResWhisper, err.Error())
3737
}

0 commit comments

Comments
 (0)