feat: 天气查询逻辑完成

This commit is contained in:
pengyinjie 2025-11-04 11:45:51 +08:00
parent 98e9410548
commit 77f5465180
4 changed files with 8 additions and 7 deletions

View File

@ -110,6 +110,7 @@ func GetWeatherConditionByIPAddr(ctx context.Context, resp *weather_and_earthqua
resp.LocationKey = key resp.LocationKey = key
condition, err := data.GetWeatherCondition(ctx, key) condition, err := data.GetWeatherCondition(ctx, key)
if err == nil && len(condition) > 0 { if err == nil && len(condition) > 0 {
//logs.Info("缓存命中:" + key)
resp.CurrentConditions = condition resp.CurrentConditions = condition
} else { } else {
condition, err = biz.GetCurrentConditions(key) condition, err = biz.GetCurrentConditions(key)

View File

@ -1,7 +1,9 @@
app_secrets: app_secrets:
- id: weatherQuery - id: weatherQuery1
secret: secret1 secret: secret1
- id: weatherQuery2 - id: weatherQuery2
secret: secret2 secret: secret2
- id: weatherQuery3 - id: weatherQuery3
secret: secret3 secret: secret3
- id: weatherQuery4
secret: secret4

View File

@ -3,7 +3,6 @@ namespace go weather_and_earthquake
struct QueryReq { struct QueryReq {
// //
// 0:
// 1: ip地址查看天气 // 1: ip地址查看天气
// 2: LocationKey LocationKey // 2: LocationKey LocationKey
// 3: Addr // 3: Addr
@ -13,7 +12,7 @@ struct QueryReq {
} }
struct QueryResp { struct QueryResp {
// 0: ip或者locationKey查询天气 // 0: ip或者locationKey查询天气
// key查询到了天气情况 // key查询到了天气情况
// -1: // -1:
// -2: // -2:
@ -26,7 +25,6 @@ struct QueryResp {
3: string Locations; 3: string Locations;
4: string CurrentConditions; 4: string CurrentConditions;
5: string DailyForecasts; 5: string DailyForecasts;
6: string EarthquakeInformations;
} }
service WeatherAndEarthquakeService { service WeatherAndEarthquakeService {

View File

@ -31,7 +31,7 @@ func InitWeatherCache(ctx context.Context, data *config.Redis) error {
// 设置某个地方的天气情况 // 设置某个地方的天气情况
func SetWeatherCondition(ctx context.Context, key, condition string) error { func SetWeatherCondition(ctx context.Context, key, condition string) error {
redis_key := fmt.Sprintf("%s-condition", key) redis_key := fmt.Sprintf("%s-condition", key)
_, err := _redis.SetNX(ctx, redis_key, condition, _expire*time.Second).Result() _, err := _redis.SetNX(ctx, redis_key, condition, _expire).Result()
return err return err
} }
@ -51,7 +51,7 @@ func GetWeatherCondition(ctx context.Context, key string) (string, error) {
// 设置某个地方的天气预报 // 设置某个地方的天气预报
func SetDailyForecasts(ctx context.Context, key, forecasts string) error { func SetDailyForecasts(ctx context.Context, key, forecasts string) error {
redis_key := fmt.Sprintf("%s-forecasts", key) redis_key := fmt.Sprintf("%s-forecasts", key)
_, err := _redis.SetNX(ctx, redis_key, forecasts, _expire*time.Second).Result() _, err := _redis.SetNX(ctx, redis_key, forecasts, _expire).Result()
return err return err
} }