Browse Source

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

Adam Weiner 10 năm trước cách đây
mục cha
commit
af5fe2490e
1 tập tin đã thay đổi với 24 bổ sung0 xóa
  1. 24 0
      frame.go

+ 24 - 0
frame.go

@@ -12,6 +12,7 @@ import (
 	"log"
 	"net"
 	"runtime"
+	"strings"
 	"sync"
 	"time"
 )
@@ -179,6 +180,29 @@ 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 "LOCAL_QUORUM":
+		return LocalQuorum
+	case "EACH_QUORUM":
+		return EachQuorum
+	case "LOCAL_ONE":
+		return LocalOne
+	default: // "ALL"
+		return All
+	}
+}
+
 type SerialConsistency uint16
 
 const (