瀏覽代碼

add ParseConsistency() to frame.go - convert text consistencies to their gocql constant

panic if invalid consistency provided

go fmt frame.go
Adam Weiner 10 年之前
父節點
當前提交
d7339ffe6a
共有 1 個文件被更改,包括 26 次插入0 次删除
  1. 26 0
      frame.go

+ 26 - 0
frame.go

@@ -12,6 +12,7 @@ import (
 	"log"
 	"net"
 	"runtime"
+	"strings"
 	"sync"
 	"time"
 )
@@ -179,6 +180,31 @@ func (c Consistency) String() string {
 	}
 }
 
+func ParseConsistency(s string) Consistency {
+	switch strings.ToUpper(s) {
+	case "ANY":
+		return Any
+	case "ONE":
+		return One
+	case "TWO":
+		return Two
+	case "THREE":
+		return Three
+	case "QUORUM":
+		return Quorum
+	case "ALL":
+		return All
+	case "LOCAL_QUORUM":
+		return LocalQuorum
+	case "EACH_QUORUM":
+		return EachQuorum
+	case "LOCAL_ONE":
+		return LocalOne
+	default:
+		panic("invalid consistency: " + s)
+	}
+}
+
 type SerialConsistency uint16
 
 const (