Skip to content

Commit

Permalink
Fix struct encode and decode for Go 1.13 (samuel#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuel authored Aug 1, 2019
1 parent 758ce21 commit d0d0e64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go
go:
- 1.11
- 1.9
- "1.11"
- "1.x"
- tip

go_import_path: github.com/samuel/go-zookeeper
Expand Down
5 changes: 3 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 @@ -404,7 +405,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 @@ -495,7 +496,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 d0d0e64

Please sign in to comment.