Skip to content

Commit

Permalink
Add Go modules + Go 1.13 support (z-division#9)
Browse files Browse the repository at this point in the history
* Add go.mod, update travis
* Fix linting errors
* Fix struct encode and decode for Go 1.13
* Make travis run on all branches
* Test against newer versions of Go
  • Loading branch information
epk authored and msolo committed Nov 11, 2019
1 parent 6d74570 commit d4903e3
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 48 deletions.
13 changes: 6 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
language: go
go:
- 1.11
- 1.9
- '1.9'
- '1.10'
- '1.11'
- '1.12'
- '1.13'
- tip

go_import_path: github.com/samuel/go-zookeeper
go_import_path: github.com/z-division/go-zookeeper

jdk:
- oraclejdk9

sudo: false

branches:
only:
- master

before_install:
- make setup ZK_VERSION=${zk_version}

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/z-division/go-zookeeper

go 1.13
6 changes: 3 additions & 3 deletions zk/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,13 @@ func (c *Conn) resendZkAuth() error {
}
resChan, err := c.sendRequest(
opSetAuth,
&setAuthRequest{Type: 0,
&setAuthRequest{
Type: 0,
Scheme: cred.scheme,
Auth: cred.auth,
},
&setAuthResponse{},
nil)

if err != nil {
c.logger.Printf("call to sendRequest failed during credential resubmit: %s", err)
return err
Expand Down Expand Up @@ -1075,7 +1075,6 @@ func (c *Conn) request(opcode int32, req interface{}, res interface{}, recvFunc

func (c *Conn) AddAuth(scheme string, auth []byte) error {
_, err := c.request(opSetAuth, &setAuthRequest{Type: 0, Scheme: scheme, Auth: auth}, &setAuthResponse{}, nil)

if err != nil {
return err
}
Expand Down Expand Up @@ -1293,6 +1292,7 @@ func (c *Conn) GetACL(path string) ([]ACL, *Stat, error) {
_, err := c.request(opGetAcl, &getAclRequest{Path: path}, res, nil)
return res.Acl, &res.Stat, err
}

func (c *Conn) SetACL(path string, acl []ACL, version int32) (*Stat, error) {
if err := validatePath(path, false); err != nil {
return nil, err
Expand Down
56 changes: 25 additions & 31 deletions zk/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ const (
EventNotWatching EventType = -2
)

var (
eventNames = map[EventType]string{
EventNodeCreated: "EventNodeCreated",
EventNodeDeleted: "EventNodeDeleted",
EventNodeDataChanged: "EventNodeDataChanged",
EventNodeChildrenChanged: "EventNodeChildrenChanged",
EventSession: "EventSession",
EventNotWatching: "EventNotWatching",
}
)
var eventNames = map[EventType]string{
EventNodeCreated: "EventNodeCreated",
EventNodeDeleted: "EventNodeDeleted",
EventNodeDataChanged: "EventNodeDataChanged",
EventNodeChildrenChanged: "EventNodeChildrenChanged",
EventSession: "EventSession",
EventNotWatching: "EventNotWatching",
}

const (
StateUnknown State = -1 // Deprecated - never generated by server.
Expand All @@ -83,20 +81,18 @@ const (
FlagSequence = 2
)

var (
stateNames = map[State]string{
StateUnknown: "StateUnknown",
StateDisconnected: "StateDisconnected",
StateSyncConnected: "StateSyncConnected",
StateConnectedReadOnly: "StateConnectedReadOnly",
StateSaslAuthenticated: "StateSaslAuthenticated",
StateExpired: "StateExpired",
StateAuthFailed: "StateAuthFailed",
StateConnecting: "StateConnecting",
StateConnected: "StateConnected",
StateHasSession: "StateHasSession",
}
)
var stateNames = map[State]string{
StateUnknown: "StateUnknown",
StateDisconnected: "StateDisconnected",
StateSyncConnected: "StateSyncConnected",
StateConnectedReadOnly: "StateConnectedReadOnly",
StateSaslAuthenticated: "StateSaslAuthenticated",
StateExpired: "StateExpired",
StateAuthFailed: "StateAuthFailed",
StateConnecting: "StateConnecting",
StateConnected: "StateConnected",
StateHasSession: "StateHasSession",
}

type State int32

Expand Down Expand Up @@ -265,10 +261,8 @@ const (
ModeStandalone Mode = iota
)

var (
modeNames = map[Mode]string{
ModeLeader: "leader",
ModeFollower: "follower",
ModeStandalone: "standalone",
}
)
var modeNames = map[Mode]string{
ModeLeader: "leader",
ModeFollower: "follower",
ModeStandalone: "standalone",
}
5 changes: 0 additions & 5 deletions zk/flw.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func FLWSrvr(servers []string, timeout time.Duration) ([]*ServerStats, bool) {

for i := range ss {
response, err := fourLetterWord(servers[i], "srvr", timeout)

if err != nil {
ss[i] = &ServerStats{Error: err}
imOk = false
Expand Down Expand Up @@ -73,15 +72,13 @@ func FLWSrvr(servers []string, timeout time.Duration) ([]*ServerStats, bool) {
}

buildTime, err := time.Parse("01/02/2006 15:04 MST", match[1])

if err != nil {
ss[i] = &ServerStats{Error: err}
imOk = false
continue
}

parsedInt, err := strconv.ParseInt(match[9], 0, 64)

if err != nil {
ss[i] = &ServerStats{Error: err}
imOk = false
Expand Down Expand Up @@ -133,7 +130,6 @@ func FLWRuok(servers []string, timeout time.Duration) []bool {

for i := range oks {
response, err := fourLetterWord(servers[i], "ruok", timeout)

if err != nil {
continue
}
Expand Down Expand Up @@ -168,7 +164,6 @@ func FLWCons(servers []string, timeout time.Duration) ([]*ServerClients, bool) {

for i := range sc {
response, err := fourLetterWord(servers[i], "cons", timeout)

if err != nil {
sc[i] = &ServerClients{Error: err}
imOk = false
Expand Down
8 changes: 6 additions & 2 deletions zk/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"
"reflect"
"runtime"
"strings"
"time"
)

Expand Down Expand Up @@ -269,16 +270,19 @@ type multiRequestOp struct {
Header multiHeader
Op interface{}
}

type multiRequest struct {
Ops []multiRequestOp
DoneHeader multiHeader
}

type multiResponseOp struct {
Header multiHeader
String string
Stat *Stat
Err ErrCode
}

type multiResponse struct {
Ops []multiResponseOp
DoneHeader multiHeader
Expand Down Expand Up @@ -415,7 +419,7 @@ type encoder interface {
func decodePacket(buf []byte, st interface{}) (n int, err error) {
defer func() {
if r := recover(); r != nil {
if e, ok := r.(runtime.Error); ok && e.Error() == "runtime error: slice bounds out of range" {
if e, ok := r.(runtime.Error); ok && strings.HasPrefix(e.Error(), "runtime error: slice bounds out of range") {
err = ErrShortBuffer
} else {
panic(r)
Expand Down Expand Up @@ -506,7 +510,7 @@ func decodePacketValue(buf []byte, v reflect.Value) (int, error) {
func encodePacket(buf []byte, st interface{}) (n int, err error) {
defer func() {
if r := recover(); r != nil {
if e, ok := r.(runtime.Error); ok && e.Error() == "runtime error: slice bounds out of range" {
if e, ok := r.(runtime.Error); ok && strings.HasPrefix(e.Error(), "runtime error: slice bounds out of range") {
err = ErrShortBuffer
} else {
panic(r)
Expand Down

0 comments on commit d4903e3

Please sign in to comment.