Golang客户端适用于Cassandra。

huangapple go评论73阅读模式
英文:

Golang client for Cassandra

问题

我正在寻找一个支持单元测试的Golang客户端,用于连接Cassandra数据库。我已经找到了一些库,如:

  1. Goosie(不再维护)
  2. gocql(没有测试支持的客户端库对我来说没有用处)
  3. gocassa(与上述问题相同)

有人可以推荐一个符合我需求的客户端库吗?

英文:

I am looking for a golang client for Cassandra with unit testing support. I have found some libraries like

  1. Goosie (not maintained any more)
  2. gocql (any client library with no testing support is useless for me)
  3. gocassa (same issue as above)

Can someone suggest me any client lib that has what I am looking for ?

答案1

得分: 2

这是我在评论中提到的一个非常简单的示例:

type CassAPI interface {
    GetFoo(rowKey string) (someType, error)
}

type CassWrapper struct {
    cass *gocql.Session
}

func (cw *CassWrapper) GetFoo(rowKey string) (someType, error) {
    // 使用 cw.cass 进行操作
    return someType, nil
}

在应用程序代码中,将使用 CassWrapper 的一个实例,在测试中将使用某个模拟或存根的实例,该实例遵循 CassAPI 的相同接口。

英文:

This is a very simple example of what I was referring to in the comments:

type CassAPI interface {
    GetFoo(rowKey string) (someType, error)
}

type CassWrapper struct {
    cass *gocql.Session
}

func (cw *CassWrapper) GetFoo(rowKey string) (someType, error) {
    // do things with cw.cass
    return someType
}

In the application code, an instance of CassWrapper would be used, and in tests an instance of some mock or stub would be used which adhered to the same interface of CassAPI.

huangapple
  • 本文由 发表于 2015年12月12日 01:03:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/34228765.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定