diff --git a/applications/comment/infra/repository/comment_hb_repo/repository.go b/applications/comment/infra/repository/comment_hb_repo/repository.go index b1aaf526..0b5df4ab 100644 --- a/applications/comment/infra/repository/comment_hb_repo/repository.go +++ b/applications/comment/infra/repository/comment_hb_repo/repository.go @@ -6,6 +6,7 @@ import ( "github.com/TremblingV5/DouTok/applications/comment/infra/model" "github.com/TremblingV5/DouTok/pkg/hbaseHandle" tools "github.com/TremblingV5/DouTok/pkg/misc" + "github.com/tsuna/gohbase" "github.com/tsuna/gohbase/hrpc" ) @@ -16,10 +17,10 @@ type Repository interface { } type PersistRepository struct { - hbClient *hbaseHandle.HBaseClient + hbClient gohbase.Client } -func New(hbClient *hbaseHandle.HBaseClient) *PersistRepository { +func New(hbClient gohbase.Client) *PersistRepository { return &PersistRepository{ hbClient: hbClient, } @@ -39,7 +40,7 @@ func (r *PersistRepository) Save(ctx context.Context, comment *model.CommentInHB }, } - if err := r.hbClient.Put( + if _, err := r.hbClient.Put( "comment", misc.GetCommentRowKey( comment.GetVideoId(), "0", comment.GetConversationId(), diff --git a/applications/comment/main.go b/applications/comment/main.go index 375ff341..59d70c12 100644 --- a/applications/comment/main.go +++ b/applications/comment/main.go @@ -14,8 +14,7 @@ import ( "github.com/TremblingV5/DouTok/pkg/dlog" "github.com/TremblingV5/DouTok/pkg/hbaseHandle" "github.com/TremblingV5/DouTok/pkg/initHelper" - "github.com/TremblingV5/DouTok/pkg/mysqlIniter" - redishandle "github.com/TremblingV5/DouTok/pkg/redisHandle" + "github.com/TremblingV5/box/components/hbasex" "github.com/TremblingV5/box/components/mysqlx" "github.com/TremblingV5/box/components/redisx" "github.com/TremblingV5/box/configx" @@ -28,45 +27,6 @@ var ( Logger = dlog.InitLog(3) ) -func initDb( - username, password, host, port, database string, -) { - db, err := mysqlIniter.InitDb( - username, - password, - host, - port, - database, - ) - - if err != nil { - panic(err) - } - - query.SetDefault(db) - - dbtx.Init(func() dbtx.TX { - return query.Q.Begin() - }) -} - -func initRedis( - dest, password string, - dbs map[string]int, -) map[string]*redishandle.RedisClient { - redisClients, err := redishandle.InitRedis( - dest, - password, - dbs, - ) - - if err != nil { - panic(err) - } - - return redisClients -} - func initHb(host string) hbaseHandle.HBaseClient { return hbaseHandle.InitHB(host) } @@ -79,13 +39,16 @@ func Init() comment.CommentService { query.SetDefault( mysqlx.GetDBClient(context.Background(), "default"), ) + dbtx.Init(func() dbtx.TX { + return query.Q.Begin() + }) hbaseClient := initHb(misc.GetConfig("HBase.Host")) service := comment_service.New( cache.NewCountMapCache(), cache.NewCountMapCache(), - comment_hb_repo.New(&hbaseClient), + comment_hb_repo.New(hbasex.GetClient(ctx, "default")), redisx.GetClient(ctx, "default", misc.ComCntCache), redisx.GetClient(ctx, "default", misc.ComTotalCntCache), ) diff --git a/go.mod b/go.mod index 9447a2ee..0bcbe804 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( bou.ke/monkey v1.0.2 github.com/IBM/sarama v1.43.1 - github.com/TremblingV5/box v0.0.5 + github.com/TremblingV5/box v0.0.7 github.com/aliyun/aliyun-oss-go-sdk v2.2.6+incompatible github.com/bwmarrin/snowflake v0.3.0 github.com/caarlos0/env/v9 v9.0.0 @@ -40,7 +40,7 @@ require ( github.com/stretchr/testify v1.9.0 github.com/swaggo/files v1.0.1 github.com/swaggo/swag v1.16.3 - github.com/tsuna/gohbase v0.0.0-20221118171731-ee78e2db30c3 + github.com/tsuna/gohbase v0.0.0-20240425232423-fa78846cafc9 go.mongodb.org/mongo-driver v1.14.0 go.uber.org/zap v1.27.0 golang.org/x/net v0.24.0