add: some user api and all api desc
This commit is contained in:
@@ -1,13 +1,55 @@
|
||||
package svc
|
||||
|
||||
import "juwan-backend/app/user_verifications/rpc/internal/config"
|
||||
import (
|
||||
"juwan-backend/app/snowflake/rpc/snowflake"
|
||||
"juwan-backend/app/user_verifications/rpc/internal/config"
|
||||
"juwan-backend/app/user_verifications/rpc/internal/models"
|
||||
"juwan-backend/app/user_verifications/rpc/userverifications"
|
||||
"juwan-backend/common/redisx"
|
||||
"juwan-backend/common/snowflakex"
|
||||
"juwan-backend/pkg/adapter"
|
||||
"time"
|
||||
|
||||
"ariga.io/entcache"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
Config config.Config
|
||||
UserVeriModelRW *models.UserVerificationsClient
|
||||
UserVeriModelRO *models.UserVerificationsClient
|
||||
RedisClient *redis.ClusterClient
|
||||
UserVeriRpc userverifications.UserVerificationsZrpcClient
|
||||
SnowflakeRpc snowflake.SnowflakeServiceClient
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
RWConn, err := sql.Open("pgx", c.DB.Master)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ROConn, err := sql.Open("pgx", c.DB.Slave)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
redisConn, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
|
||||
if err != nil || redisConn == nil {
|
||||
logx.Errorf("redis connect master error: %s", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
RWDrv := entcache.NewDriver(RWConn, entcache.TTL(time.Second*30), entcache.Levels(adapter.NewRedisCache(redisConn.Client)))
|
||||
RODrv := entcache.NewDriver(ROConn, entcache.TTL(time.Second*30), entcache.Levels(adapter.NewRedisCache(redisConn.Client)))
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
Config: c,
|
||||
UserVeriModelRW: models.NewClient(models.Driver(RWDrv)).UserVerifications,
|
||||
UserVeriModelRO: models.NewClient(models.Driver(RODrv)).UserVerifications,
|
||||
RedisClient: redisConn.Client,
|
||||
UserVeriRpc: userverifications.NewUserVerificationsZrpcClient(zrpc.MustNewClient(c.UserVeriRpcConf)),
|
||||
SnowflakeRpc: snowflakex.NewClient(c.SnowflakeRpcConf),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user