update
This commit is contained in:
parent
fdfca62b75
commit
754c4899ad
|
|
@ -11,17 +11,17 @@ var _redis *redis.Client
|
|||
var _expire time.Duration
|
||||
|
||||
// 初始化 redis 连接
|
||||
func InitWeatherCache(ctx context.Context, data *config.Data) error {
|
||||
func InitWeatherCache(ctx context.Context, data *config.Redis) error {
|
||||
_redis = redis.NewClient(&redis.Options{
|
||||
Addr: data.Redis.Addr,
|
||||
Password: data.Redis.Password,
|
||||
DB: data.Redis.DB,
|
||||
ReadTimeout: data.Redis.ReadTimeout * time.Second,
|
||||
WriteTimeout: data.Redis.WriteTimeout * time.Second,
|
||||
PoolSize: data.Redis.PoolSize,
|
||||
MinIdleConns: data.Redis.MinIdleConns,
|
||||
Addr: data.Addr,
|
||||
Password: data.Password,
|
||||
DB: data.DB,
|
||||
ReadTimeout: data.ReadTimeout * time.Second,
|
||||
WriteTimeout: data.WriteTimeout * time.Second,
|
||||
PoolSize: data.PoolSize,
|
||||
MinIdleConns: data.MinIdleConns,
|
||||
})
|
||||
_expire = data.Redis.Expire
|
||||
_expire = data.Expire
|
||||
|
||||
_, err := _redis.Ping(ctx).Result()
|
||||
return err
|
||||
|
|
|
|||
17
main.go
17
main.go
|
|
@ -3,6 +3,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/cloudwego/hertz/pkg/app/server"
|
||||
|
|
@ -61,14 +62,11 @@ func initialize() {
|
|||
|
||||
biz.AccuWeather = conf.AccuWeather
|
||||
middleware.Apps = apps
|
||||
data.DataConf = conf.Data
|
||||
err = data.InitWeatherCache(context.Background(), conf.Data.Redis)
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
|
||||
log.Println("LogLevel=", conf.Server.LogLevel)
|
||||
logs.SetFile("./logs/logs.log")
|
||||
logs.Warn("Logs warning")
|
||||
logs.Error("Logs error")
|
||||
logs.Info("Logs info")
|
||||
logs.Debug("Logs debug")
|
||||
switch conf.Server.LogLevel {
|
||||
case 1:
|
||||
logs.SetLevel(logs.LINFO)
|
||||
|
|
@ -79,6 +77,11 @@ func initialize() {
|
|||
default:
|
||||
logs.SetLevel(logs.LDEBUG)
|
||||
}
|
||||
logs.SetFile("./logs/logs.log")
|
||||
logs.Warn("Logs warning")
|
||||
logs.Error("Logs error")
|
||||
logs.Info("Logs info")
|
||||
logs.Debug("Logs debug")
|
||||
|
||||
hostPort := fmt.Sprintf("%s:%d", conf.Server.Addr, conf.Server.Port)
|
||||
_server = server.Default(server.WithHostPorts(hostPort))
|
||||
|
|
|
|||
Loading…
Reference in New Issue