newclient.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package odbc
  2. import (
  3. "fmt"
  4. "runtime"
  5. "strings"
  6. ccfg "git.wecise.com/wecise/common/matrix/cfg"
  7. clog "git.wecise.com/wecise/common/matrix/logger"
  8. "git.wecise.com/wecise/odb-go/odb"
  9. "github.com/scylladb/go-set/strset"
  10. )
  11. var cfg = ccfg.MConfig()
  12. var log = clog.New().WithConfig(cfg, "log")
  13. func init() {
  14. log.Info("cpu limit", 1)
  15. runtime.GOMAXPROCS(1)
  16. }
  17. var odbcfg *odb.Config
  18. func init() {
  19. odbpath := cfg.GetStrings("ODBPATH", "127.0.0.1:11001,47.92.151.165:11001")
  20. keyspace := cfg.GetString("KEYSPACE", "oktest")
  21. poolsize := cfg.GetInt("POOLSIZE", 0)
  22. odbpaths := strset.New()
  23. for _, p := range odbpath {
  24. odbpaths.Add(strings.Split(p, ",")...)
  25. }
  26. odbcfg = &odb.Config{
  27. Hosts: odbpaths.List(),
  28. Keyspace: keyspace,
  29. User: fmt.Sprint("测试客户端", cfg.GetString("N")),
  30. Pass: "********",
  31. PoolSize: poolsize,
  32. Debug: true,
  33. }
  34. }
  35. func Config() *odb.Config {
  36. return odbcfg
  37. }
  38. func NewClient() (c odb.Client, err error) {
  39. client, err := odb.NewClient(odbcfg)
  40. if err != nil {
  41. return nil, err
  42. }
  43. return client, nil
  44. }