diff --git a/client/client.go b/client/client.go index 5e12dbb..5e019bf 100644 --- a/client/client.go +++ b/client/client.go @@ -192,7 +192,7 @@ func (client *Client) do(funcname string, data []byte, handle = resp.Handle mutex.Unlock() } - id := IdGen.Id() + id := IdGen.Id(funcname, string(data)) req := getJob(id, []byte(funcname), data) req.DataType = flag client.write(req) diff --git a/client/id.go b/client/id.go index 4c92e99..1e7c43f 100644 --- a/client/id.go +++ b/client/id.go @@ -16,10 +16,10 @@ func init() { IdGen = NewAutoIncId() } -// ID generator interface. Users can implament this for +// ID generator interface. Users can implement this for // their own generator. type IdGenerator interface { - Id() string + Id(funcname, payload string) string } // AutoIncId @@ -27,7 +27,7 @@ type autoincId struct { value int64 } -func (ai *autoincId) Id() string { +func (ai *autoincId) Id(funcname, payload string) string { next := atomic.AddInt64(&ai.value, 1) return strconv.FormatInt(next, 10) } diff --git a/client/id_test.go b/client/id_test.go index 399d217..d745380 100644 --- a/client/id_test.go +++ b/client/id_test.go @@ -7,9 +7,9 @@ import ( func TestAutoInc(t *testing.T) { ai := NewAutoIncId() - previous := ai.Id() + previous := ai.Id("testfuncname", "fakepayload") for i := 0; i < 10; i++ { - id := ai.Id() + id := ai.Id("testfuncname", "fakepayload2") if id == previous { t.Errorf("Id not unique, previous and current %s", id) }