feat: 天气查询逻辑完成
This commit is contained in:
parent
98e9410548
commit
77f5465180
|
|
@ -110,6 +110,7 @@ func GetWeatherConditionByIPAddr(ctx context.Context, resp *weather_and_earthqua
|
|||
resp.LocationKey = key
|
||||
condition, err := data.GetWeatherCondition(ctx, key)
|
||||
if err == nil && len(condition) > 0 {
|
||||
//logs.Info("缓存命中:" + key)
|
||||
resp.CurrentConditions = condition
|
||||
} else {
|
||||
condition, err = biz.GetCurrentConditions(key)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
app_secrets:
|
||||
- id: weatherQuery
|
||||
- id: weatherQuery1
|
||||
secret: secret1
|
||||
- id: weatherQuery2
|
||||
secret: secret2
|
||||
- id: weatherQuery3
|
||||
secret: secret3
|
||||
- id: weatherQuery4
|
||||
secret: secret4
|
||||
|
|
@ -3,7 +3,6 @@ namespace go weather_and_earthquake
|
|||
|
||||
struct QueryReq {
|
||||
// 操作码
|
||||
// 0: 查最新地震信息。
|
||||
// 1: 默认情况,通过ip地址查看天气。此时不需要其他参数。
|
||||
// 2: 通过提供的 LocationKey 查看天气。需要提供 LocationKey。
|
||||
// 3: 通过地名查看天气。需要提供 Addr。
|
||||
|
|
@ -13,7 +12,7 @@ struct QueryReq {
|
|||
}
|
||||
|
||||
struct QueryResp {
|
||||
// 0: 成功。如果是地震信息,就返回地震信息。如果是通过ip或者locationKey查询天气,就返回当前情况和预报。
|
||||
// 0: 成功。如果是通过ip或者locationKey查询天气,就返回当前情况和预报。
|
||||
// 如果是通过地点查询,表示查到地点,并且只有一个,且通过这个key查询到了天气情况。
|
||||
// -1: 参数错误
|
||||
// -2: 请求头参数错误
|
||||
|
|
@ -26,7 +25,6 @@ struct QueryResp {
|
|||
3: string Locations;
|
||||
4: string CurrentConditions;
|
||||
5: string DailyForecasts;
|
||||
6: string EarthquakeInformations;
|
||||
}
|
||||
|
||||
service WeatherAndEarthquakeService {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func InitWeatherCache(ctx context.Context, data *config.Redis) error {
|
|||
// 设置某个地方的天气情况
|
||||
func SetWeatherCondition(ctx context.Context, key, condition string) error {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +51,7 @@ func GetWeatherCondition(ctx context.Context, key string) (string, error) {
|
|||
// 设置某个地方的天气预报
|
||||
func SetDailyForecasts(ctx context.Context, key, forecasts string) error {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue