Example #1
0
func parseConsistency(s string) (c gocql.Consistency, err error) {
	defer func() {
		if r := recover(); r != nil {
			err = &ErrInvalidConfig{
				Message: "unknown consistency",
				Value:   s,
			}
		}
	}()

	c = gocql.ParseConsistency(s)
	return c, err
}
Example #2
0
// ParseConsistency wraps gocql.ParseConsistency to return an error
// instead of a panicing.
func parseConsistency(consistencyStr string) (consistency gocql.Consistency, err error) {
	defer func() {
		if r := recover(); r != nil {
			var ok bool
			err, ok = r.(error)
			if !ok {
				err = fmt.Errorf("Failed to parse consistency \"%s\": %v", consistencyStr, r)
			}
		}
	}()
	consistency = gocql.ParseConsistency(consistencyStr)

	return consistency, nil
}
func newCassandraBackend(conf *Conf) IBackend {
	// Connect to the cluster
	cluster := gocql.NewCluster(conf.Cassandra.Hosts...)
	cluster.Keyspace = conf.Cassandra.Keyspace
	cluster.Consistency = gocql.ParseConsistency(conf.Cassandra.Consistency)
	cluster.ProtoVersion = conf.Cassandra.ProtoVersion

	session, err := cluster.CreateSession()
	if err != nil {
		log.Fatal(err)
	}

	return CassandraBackend{
		session: session,
		config:  conf.Cassandra,
	}
}