From f2fcc09e6188f2515e1fc2f744e8560857874f82 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Sun, 13 Sep 2020 14:14:13 +0200 Subject: [PATCH] Implement NewDiskClient. --- disk.go | 19 +++++++++++++++++++ webclient.go | 5 +---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/disk.go b/disk.go index f9a8db6..880bd49 100644 --- a/disk.go +++ b/disk.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "strconv" "sync" "time" @@ -24,6 +25,24 @@ type diskClient struct { closed bool } +var idCounter struct { + mu sync.Mutex + counter int +} + +func newId() string { + idCounter.mu.Lock() + defer idCounter.mu.Unlock() + + s := strconv.FormatInt(int64(idCounter.counter), 16) + idCounter.counter++ + return s +} + +func NewDiskClient(g *group) *diskClient { + return &diskClient{group: g, id: newId()} +} + func (client *diskClient) Group() *group { return client.group } diff --git a/webclient.go b/webclient.go index 5f50531..7b81959 100644 --- a/webclient.go +++ b/webclient.go @@ -1078,10 +1078,7 @@ func handleClientMessage(c *webClient, m clientMessage) error { return c.error(userError("already recording")) } } - disk := &diskClient{ - group: c.group, - id: "recording", - } + disk := NewDiskClient(c.group) _, err := addClient(c.group.name, disk) if err != nil { disk.Close()