You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.6 KiB
80 lines
1.6 KiB
2 months ago
|
package service
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"github.com/TremblingV5/DouTok/applications/feed/misc"
|
||
|
"github.com/TremblingV5/DouTok/pkg/constants"
|
||
|
"github.com/TremblingV5/DouTok/pkg/utils"
|
||
|
|
||
|
"github.com/TremblingV5/DouTok/applications/feed/dal/query"
|
||
|
"github.com/TremblingV5/DouTok/pkg/hbaseHandle"
|
||
|
"github.com/TremblingV5/DouTok/pkg/mysqlIniter"
|
||
|
redishandle "github.com/TremblingV5/DouTok/pkg/redisHandle"
|
||
|
)
|
||
|
|
||
|
func Init() {
|
||
|
misc.InitViperConfig()
|
||
|
|
||
|
InitDb(
|
||
|
misc.GetConfig("MySQL.Username"),
|
||
|
misc.GetConfig("MySQL.Password"),
|
||
|
misc.GetConfig("MySQL.Host"),
|
||
|
misc.GetConfig("MySQL.Port"),
|
||
|
misc.GetConfig("MySQL.Database"),
|
||
|
)
|
||
|
|
||
|
InitHB(
|
||
|
misc.GetConfig("HBase.Host"),
|
||
|
)
|
||
|
|
||
|
redisMap := map[string]int{
|
||
|
constants.FeedSendBox: int(misc.GetConfigNum("Redis.SendBox.Num")),
|
||
|
constants.TimeCache: int(misc.GetConfigNum("Redis.MarkdedTime.Num")),
|
||
|
}
|
||
|
InitRedis(
|
||
|
misc.GetConfig("Redis.Dest"),
|
||
|
misc.GetConfig("Redis.Password"),
|
||
|
redisMap,
|
||
|
)
|
||
|
utils.InitSnowFlake(misc.GetConfigNum("Snowflake.Node"))
|
||
|
}
|
||
|
|
||
|
func InitDb(username string, password string, host string, port string, database string) error {
|
||
|
db, err := mysqlIniter.InitDb(
|
||
|
username,
|
||
|
password,
|
||
|
host,
|
||
|
port,
|
||
|
database,
|
||
|
)
|
||
|
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
DB = db
|
||
|
|
||
|
query.SetDefault(DB)
|
||
|
Video = query.Video
|
||
|
Do = Video.WithContext(context.Background())
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func InitHB(host string) error {
|
||
|
client := hbaseHandle.InitHB(host)
|
||
|
HBClient = &client
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func InitRedis(dest string, password string, dbs map[string]int) error {
|
||
|
redisCaches, _ := redishandle.InitRedis(
|
||
|
dest, password, dbs,
|
||
|
)
|
||
|
|
||
|
RedisClients = redisCaches
|
||
|
|
||
|
return nil
|
||
|
}
|