diff options
author | Christian Pointner <equinox@spreadspace.org> | 2017-05-07 21:58:18 +0200 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2017-05-07 21:58:18 +0200 |
commit | a13dcad6072debed67b554edb31535d39b179fff (patch) | |
tree | c198707446995a3ddca0840912556ee0b27bd40b /src/hub | |
parent | use reader/writer interface for fowarder (diff) |
minor cleanup
Diffstat (limited to 'src/hub')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5srvForward.go | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5srvForward.go b/src/hub/src/spreadspace.org/sfive/s5srvForward.go index a479c2e..eeb2352 100644 --- a/src/hub/src/spreadspace.org/sfive/s5srvForward.go +++ b/src/hub/src/spreadspace.org/sfive/s5srvForward.go @@ -77,6 +77,22 @@ func fwdGetLastUpdate(baseurl string, client *http.Client, hubUuid string) (last return } +func fwdWriteUpdates(updates []DataUpdateFull, pw *io.PipeWriter) { + defer pw.Close() + + enc, err := NewStatefulEncoder(pw) + if err != nil { + s5l.Printf("fwd: failed encoding/sending init message: %v", err) + return + } + for _, upd := range updates { + if err := enc.Encode(upd); err != nil { + s5l.Printf("fwd: failed encoding/sending updates: %v", err) + return + } + } +} + func fwdPostUpdates(client *http.Client, url string, pr *io.PipeReader) (int, error) { resp, err := client.Post(url, "application/json", pr) if err != nil { @@ -126,22 +142,7 @@ tryResync: } pr, pw := io.Pipe() - go func(pw *io.PipeWriter) { - defer pw.Close() - - enc, err := NewStatefulEncoder(pw) - if err != nil { - s5l.Printf("fwd: failed encoding/sending init message: %v", err) - return - } - for _, upd := range updates { - if err := enc.Encode(upd); err != nil { - s5l.Printf("fwd: failed encoding/sending updates: %v", err) - return - } - } - }(pw) - + go fwdWriteUpdates(updates, pw) if num, err := fwdPostUpdates(client, url, pr); err != nil { s5l.Printf("fwd: failed sending updates: %v", err) continue tryResync |