Browse Source

add other StoreHost support

pull/202/head
yedf2 5 years ago
parent
commit
d7b8949ac2
  1. 5
      test/busi/base_types.go
  2. 6
      test/busi/utils.go

5
test/busi/base_types.go

@ -17,10 +17,13 @@ import (
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
) )
// StoreHost examples will connect to dtm.pub; tests will connect to localhost
var StoreHost = "localhost"
// BusiConf 1 // BusiConf 1
var BusiConf = dtmcli.DBConf{ var BusiConf = dtmcli.DBConf{
Driver: "mysql", Driver: "mysql",
Host: "localhost", Host: StoreHost,
Port: 3306, Port: 3306,
User: "root", User: "root",
} }

6
test/busi/utils.go

@ -5,7 +5,6 @@ import (
"database/sql" "database/sql"
"encoding/json" "encoding/json"
"fmt" "fmt"
"os"
"strings" "strings"
sync "sync" sync "sync"
"time" "time"
@ -130,7 +129,7 @@ func RedisGet() *redis.Client {
once.Do(func() { once.Do(func() {
logger.Debugf("connecting to client redis") logger.Debugf("connecting to client redis")
rdb = redis.NewClient(&redis.Options{ rdb = redis.NewClient(&redis.Options{
Addr: dtmimp.OrString(os.Getenv("BUSI_REDIS"), "localhost:6379"), Addr: fmt.Sprintf("%s:6379", StoreHost),
Username: "root", Username: "root",
Password: "", Password: "",
}) })
@ -146,8 +145,9 @@ var (
// MongoGet get mongo client // MongoGet get mongo client
func MongoGet() *mongo.Client { func MongoGet() *mongo.Client {
mongoOnce.Do(func() { mongoOnce.Do(func() {
uri := fmt.Sprintf("mongodb://%s:27017/?retryWrites=false", StoreHost)
ctx := context.Background() ctx := context.Background()
client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017/?retryWrites=false")) client, err := mongo.Connect(ctx, options.Client().ApplyURI(uri))
dtmimp.E2P(err) dtmimp.E2P(err)
mongoc = client mongoc = client
}) })

Loading…
Cancel
Save