Skip to content

Commit

Permalink
Stylistic cleanup (i.e. golint)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel committed Mar 12, 2014
1 parent 8edc763 commit e0b28c8
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
22 changes: 11 additions & 11 deletions zk/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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{}
Expand All @@ -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])
Expand Down
6 changes: 3 additions & 3 deletions zk/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand Down Expand Up @@ -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) // *
Expand Down
2 changes: 1 addition & 1 deletion zk/server_help.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions zk/server_java.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
)

type ServerConfigServer struct {
Id int
ID int
Host string
PeerPort int
LeaderElectionPort int
Expand Down Expand Up @@ -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
Expand Down
50 changes: 25 additions & 25 deletions zk/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
type ACL struct {
Perms int32
Scheme string
Id string
ID string
}

type Stat struct {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand All @@ -246,25 +246,25 @@ 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
}

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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions zk/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion zk/zk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e0b28c8

Please sign in to comment.