From b1466a3e482c88840f149aae90432bc815817903 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Wed, 24 Apr 2019 14:03:13 -0600 Subject: [PATCH] I got it. Hash shouldnt be tied to addr. --- client/cli.go | 2 +- client/client.go | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/client/cli.go b/client/cli.go index 1013a31..7df8a72 100644 --- a/client/cli.go +++ b/client/cli.go @@ -11,7 +11,7 @@ import ( func main() { as := args.NewArgSet() - as.Append(args.STRING, "addr", "csv addr(s) of server(s)", "http://localhost:21412") + as.Append(args.STRING, "addr", "csv key;addr(s) of server(s)", "key;http://localhost:21412") as.Append(args.INT, "r", "read concern", 1) as.Append(args.INT, "w", "write concern", 1) if err := as.Parse(); err != nil { diff --git a/client/client.go b/client/client.go index b16ac28..b2cbe4a 100644 --- a/client/client.go +++ b/client/client.go @@ -29,7 +29,17 @@ func (h hasher) Sum64(data []byte) uint64 { type netAddr string func (na netAddr) String() string { - return string(na) + return strings.Split(string(na), ";")[0] +} + +func (na netAddr) Addr() string { + ind := strings.Index(string(na), ";") + if ind < 0 { + ind = 0 + } else { + ind += 1 + } + return string(na)[ind:] } func (na netAddr) Network() string { @@ -72,7 +82,7 @@ func New(rConcern, wConcern int, addrs ...string) (*Client, error) { hash.Add(netAddr(addr)) } for _, addr := range hash.GetMembers() { - conn, err := net.Dial("tcp", strings.TrimPrefix(strings.TrimPrefix(addr.String(), "http://"), "https://")) + conn, err := net.Dial("tcp", strings.TrimPrefix(strings.TrimPrefix(addr.(netAddr).Addr(), "http://"), "https://")) if err != nil { return nil, err } @@ -99,7 +109,7 @@ func (c *Client) scatterGather(key string, forEach func(addr string, each chan r return nil, err } for _, member := range members { - go forEach(member.String(), each) + go forEach(member.(netAddr).Addr(), each) } go func() { out := make(map[string]int)