浏览代码

Fix breaking change introduced in #983

Evan Culver 8 年之前
父节点
当前提交
939af06b39
共有 1 个文件被更改,包括 17 次插入7 次删除
  1. 17 7
      frame.go

+ 17 - 7
frame.go

@@ -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