Skip to content

Commit

Permalink
Merge pull request apache#1002 from eculver/parse_consistency
Browse files Browse the repository at this point in the history
Fix breaking change introduced in apache#983
  • Loading branch information
Zariel authored Oct 26, 2017
2 parents 720df24 + 939af06 commit f52d33c
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,30 @@ func (c *Consistency) UnmarshalText(text []byte) error {
return nil
}

func ParseConsistency(s string) (consistency Consistency, err error) {
func ParseConsistency(s string) Consistency {
var c Consistency
if err := c.UnmarshalText([]byte(strings.ToUpper(s))); err != nil {
panic(err)
}
return c
}

// ParseConsistencyWrapper wraps gocql.ParseConsistency to provide an err
// return instead of a panic
func ParseConsistencyWrapper(s string) (consistency Consistency, err error) {
err = consistency.UnmarshalText([]byte(strings.ToUpper(s)))
return
}

// ParseConsistencyWrapper is deprecated use ParseConsistency instead.
var ParseConsistencyWrapper = ParseConsistency

func MustParseConsistency(s string) Consistency {
c, err := ParseConsistency(s)
// MustParseConsistency is the same as ParseConsistency except it returns
// an error (never). It is kept here since breaking changes are not good.
// DEPRECATED: use ParseConsistency if you want a panic on parse error.
func MustParseConsistency(s string) (Consistency, error) {
c, err := ParseConsistencyWrapper(s)
if err != nil {
panic(err)
}
return c
return c, nil
}

type SerialConsistency uint16
Expand Down

0 comments on commit f52d33c

Please sign in to comment.