diff --git a/zk/conn.go b/zk/conn.go index 53aa0e33..8f9c5605 100644 --- a/zk/conn.go +++ b/zk/conn.go @@ -46,7 +46,7 @@ type Dialer func(network, address string, timeout time.Duration) (net.Conn, erro type Conn struct { lastZxid int64 - sessionId int64 + sessionID int64 state State // must be 32-bit aligned xid int32 timeout int32 // session timeout in seconds @@ -326,7 +326,7 @@ func (c *Conn) authenticate() error { ProtocolVersion: protocolVersion, LastZxidSeen: c.lastZxid, TimeOut: c.timeout, - SessionId: c.sessionId, + SessionID: c.sessionID, Passwd: c.passwd, }) if err != nil { @@ -365,19 +365,19 @@ func (c *Conn) authenticate() error { if err != nil { return err } - if r.SessionId == 0 { - c.sessionId = 0 + if r.SessionID == 0 { + c.sessionID = 0 c.passwd = emptyPassword c.lastZxid = 0 c.setState(StateExpired) return ErrSessionExpired } - if c.sessionId != r.SessionId { + if c.sessionID != r.SessionID { atomic.StoreInt32(&c.xid, 0) } c.timeout = r.TimeOut - c.sessionId = r.SessionId + c.sessionID = r.SessionID c.passwd = r.Passwd c.setState(StateHasSession) @@ -612,7 +612,7 @@ func (c *Conn) Get(path string) ([]byte, *Stat, error) { return res.Data, &res.Stat, err } -// Get the contents of a znode and set a watch +// GetW returns the contents of a znode and sets a watch func (c *Conn) GetW(path string) ([]byte, *Stat, <-chan Event, error) { var ech <-chan Event res := &getDataResponse{} @@ -639,10 +639,10 @@ func (c *Conn) Create(path string, data []byte, flags int32, acl []ACL) (string, return res.Path, err } -// Fixes a race condition if the server crashes after it creates the node. On -// reconnect the session may still be valid so the ephemeral node still exists. -// Therefore, on reconnect we need to check if a node with a GUID generated on -// create exists. +// CreateProtectedEphemeralSequential fixes a race condition if the server crashes +// after it creates the node. On reconnect the session may still be valid so the +// ephemeral node still exists. Therefore, on reconnect we need to check if a node +// with a GUID generated on create exists. func (c *Conn) CreateProtectedEphemeralSequential(path string, data []byte, acl []ACL) (string, error) { var guid [16]byte _, err := io.ReadFull(rand.Reader, guid[:16]) diff --git a/zk/constants.go b/zk/constants.go index c4931eba..ee877243 100644 --- a/zk/constants.go +++ b/zk/constants.go @@ -102,7 +102,7 @@ type ErrCode int32 var ( ErrConnectionClosed = errors.New("zk: connection closed") ErrUnknown = errors.New("zk: unknown error") - ErrApiError = errors.New("zk: api error") + ErrAPIError = errors.New("zk: api error") ErrNoNode = errors.New("zk: node does not exist") ErrNoAuth = errors.New("zk: not authenticated") ErrBadVersion = errors.New("zk: version conflict") @@ -119,7 +119,7 @@ var ( // ErrInvalidCallback = errors.New("zk: invalid callback specified") errCodeToError = map[ErrCode]error{ 0: nil, - errApiError: ErrApiError, + errAPIError: ErrAPIError, errNoNode: ErrNoNode, errNoAuth: ErrNoAuth, errBadVersion: ErrBadVersion, @@ -156,7 +156,7 @@ const ( errBadArguments = -8 errInvalidState = -9 // API errors - errApiError = ErrCode(-100) + errAPIError = ErrCode(-100) errNoNode = ErrCode(-101) // * errNoAuth = ErrCode(-102) errBadVersion = ErrCode(-103) // * diff --git a/zk/server_help.go b/zk/server_help.go index 27814aa1..3c2df5c9 100644 --- a/zk/server_help.go +++ b/zk/server_help.go @@ -45,7 +45,7 @@ func StartTestCluster(size int) (*TestCluster, error) { } for i := 0; i < size; i++ { cfg.Servers = append(cfg.Servers, ServerConfigServer{ - Id: i + 1, + ID: i + 1, Host: "127.0.0.1", PeerPort: startPort + i*3 + 1, LeaderElectionPort: startPort + i*3 + 2, diff --git a/zk/server_java.go b/zk/server_java.go index 1944119e..ec892a3c 100644 --- a/zk/server_java.go +++ b/zk/server_java.go @@ -24,7 +24,7 @@ const ( ) type ServerConfigServer struct { - Id int + ID int Host string PeerPort int LeaderElectionPort int @@ -77,7 +77,7 @@ func (sc ServerConfig) Marshall(w io.Writer) error { if srv.LeaderElectionPort <= 0 { srv.LeaderElectionPort = DefaultLeaderElectionPort } - fmt.Fprintf(w, "server.%d=%s:%d:%d\n", srv.Id, srv.Host, srv.PeerPort, srv.LeaderElectionPort) + fmt.Fprintf(w, "server.%d=%s:%d:%d\n", srv.ID, srv.Host, srv.PeerPort, srv.LeaderElectionPort) } } return nil diff --git a/zk/structs.go b/zk/structs.go index 916aaeba..fd1285e4 100644 --- a/zk/structs.go +++ b/zk/structs.go @@ -16,7 +16,7 @@ var ( type ACL struct { Perms int32 Scheme string - Id string + ID string } type Stat struct { @@ -90,14 +90,14 @@ type connectRequest struct { ProtocolVersion int32 LastZxidSeen int64 TimeOut int32 - SessionId int64 + SessionID int64 Passwd []byte } type connectResponse struct { ProtocolVersion int32 TimeOut int32 - SessionId int64 + SessionID int64 Passwd []byte } @@ -224,18 +224,18 @@ func (r *multiRequest) Encode(buf []byte) (int, error) { total := 0 for _, op := range r.Ops { op.Header.Done = false - if n, err := encodePacketValue(buf[total:], reflect.ValueOf(op)); err != nil { + n, err := encodePacketValue(buf[total:], reflect.ValueOf(op)) + if err != nil { return total, err - } else { - total += n } + total += n } r.DoneHeader.Done = true - if n, err := encodePacketValue(buf[total:], reflect.ValueOf(r.DoneHeader)); err != nil { + n, err := encodePacketValue(buf[total:], reflect.ValueOf(r.DoneHeader)) + if err != nil { return total, err - } else { - total += n } + total += n return total, nil } @@ -246,11 +246,11 @@ func (r *multiRequest) Decode(buf []byte) (int, error) { total := 0 for { header := &multiHeader{} - if n, err := decodePacketValue(buf[total:], reflect.ValueOf(header)); err != nil { + n, err := decodePacketValue(buf[total:], reflect.ValueOf(header)) + if err != nil { return total, err - } else { - total += n } + total += n if header.Done { r.DoneHeader = *header break @@ -258,13 +258,13 @@ func (r *multiRequest) Decode(buf []byte) (int, error) { req := requestStructForOp(header.Type) if req == nil { - return total, ErrApiError + return total, ErrAPIError } - if n, err := decodePacketValue(buf[total:], reflect.ValueOf(req)); err != nil { + n, err = decodePacketValue(buf[total:], reflect.ValueOf(req)) + if err != nil { return total, err - } else { - total += n } + total += n r.Ops = append(r.Ops, multiRequestOp{*header, req}) } return total, nil @@ -276,11 +276,11 @@ func (r *multiResponse) Decode(buf []byte) (int, error) { total := 0 for { header := &multiHeader{} - if n, err := decodePacketValue(buf[total:], reflect.ValueOf(header)); err != nil { + n, err := decodePacketValue(buf[total:], reflect.ValueOf(header)) + if err != nil { return total, err - } else { - total += n } + total += n if header.Done { r.DoneHeader = *header break @@ -290,7 +290,7 @@ func (r *multiResponse) Decode(buf []byte) (int, error) { var w reflect.Value switch header.Type { default: - return total, ErrApiError + return total, ErrAPIError case opCreate: w = reflect.ValueOf(&res.String) case opSetData: @@ -299,11 +299,11 @@ func (r *multiResponse) Decode(buf []byte) (int, error) { case opCheck, opDelete: } if w.IsValid() { - if n, err := decodePacketValue(buf[total:], w); err != nil { + n, err := decodePacketValue(buf[total:], w) + if err != nil { return total, err - } else { - total += n } + total += n } r.Ops = append(r.Ops, res) } @@ -374,7 +374,7 @@ func decodePacketValue(buf []byte, v reflect.Value) (int, error) { } case reflect.Bool: v.SetBool(buf[n] != 0) - n += 1 + n++ case reflect.Int32: v.SetInt(int64(binary.BigEndian.Uint32(buf[n : n+4]))) n += 4 @@ -464,7 +464,7 @@ func encodePacketValue(buf []byte, v reflect.Value) (int, error) { } else { buf[n] = 0 } - n += 1 + n++ case reflect.Int32: binary.BigEndian.PutUint32(buf[n:n+4], uint32(v.Int())) n += 4 diff --git a/zk/tracer.go b/zk/tracer.go index c23d60a7..ab7e14ec 100644 --- a/zk/tracer.go +++ b/zk/tracer.go @@ -33,8 +33,8 @@ func trace(conn1, conn2 net.Conn, client bool) { return } - var cr interface{} = nil - var opcode int32 = -1 + var cr interface{} + opcode := int32(-1) readHeader := true if client { if init { diff --git a/zk/zk_test.go b/zk/zk_test.go index 01a6c7c7..055001d0 100644 --- a/zk/zk_test.go +++ b/zk/zk_test.go @@ -356,7 +356,7 @@ func TestExpiringWatch(t *testing.T) { t.Fatal("Children should return at least 1 child") } - zk.sessionId = 99999 + zk.sessionID = 99999 zk.conn.Close() select {