Compare commits
2 Commits
98e9410548
...
6936f99770
| Author | SHA1 | Date |
|---|---|---|
|
|
6936f99770 | |
|
|
77f5465180 |
|
|
@ -29,10 +29,6 @@ func QueryMethod(ctx context.Context, c *app.RequestContext) {
|
|||
logs.Info("QueryMethod req: %v", req)
|
||||
resp := new(weather_and_earthquake.QueryResp)
|
||||
switch req.Op {
|
||||
case 0:
|
||||
// 获取地震信息
|
||||
resp.Code = 0
|
||||
resp.EarthquakeInformations = biz.GetEarthquakeInfo()
|
||||
case 1:
|
||||
// 通过ip地址查天气,不需要其他参数
|
||||
ip := c.ClientIP()
|
||||
|
|
@ -110,6 +106,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)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
|
||||
type QueryReq struct {
|
||||
// 操作码
|
||||
// 0: 查最新地震信息。
|
||||
// 1: 默认情况,通过ip地址查看天气。此时不需要其他参数。
|
||||
// 2: 通过提供的 LocationKey 查看天气。需要提供 LocationKey。
|
||||
// 3: 通过地名查看天气。需要提供 Addr。
|
||||
|
|
@ -247,7 +246,7 @@ func (p *QueryReq) String() string {
|
|||
}
|
||||
|
||||
type QueryResp struct {
|
||||
// 0: 成功。如果是地震信息,就返回地震信息。如果是通过ip或者locationKey查询天气,就返回当前情况和预报。
|
||||
// 0: 成功。如果是通过ip或者locationKey查询天气,就返回当前情况和预报。
|
||||
// 如果是通过地点查询,表示查到地点,并且只有一个,且通过这个key查询到了天气情况。
|
||||
// -1: 参数错误
|
||||
// -2: 请求头参数错误
|
||||
|
|
@ -255,12 +254,11 @@ type QueryResp struct {
|
|||
// 1: 查询天气失败
|
||||
// 2: 查询地名失败
|
||||
// 3: 根据地名查询到多个地址,需要确认。
|
||||
Code int32 `thrift:"Code,1" form:"Code" json:"Code" query:"Code"`
|
||||
LocationKey string `thrift:"LocationKey,2" form:"LocationKey" json:"LocationKey" query:"LocationKey"`
|
||||
Locations string `thrift:"Locations,3" form:"Locations" json:"Locations" query:"Locations"`
|
||||
CurrentConditions string `thrift:"CurrentConditions,4" form:"CurrentConditions" json:"CurrentConditions" query:"CurrentConditions"`
|
||||
DailyForecasts string `thrift:"DailyForecasts,5" form:"DailyForecasts" json:"DailyForecasts" query:"DailyForecasts"`
|
||||
EarthquakeInformations string `thrift:"EarthquakeInformations,6" form:"EarthquakeInformations" json:"EarthquakeInformations" query:"EarthquakeInformations"`
|
||||
Code int32 `thrift:"Code,1" form:"Code" json:"Code" query:"Code"`
|
||||
LocationKey string `thrift:"LocationKey,2" form:"LocationKey" json:"LocationKey" query:"LocationKey"`
|
||||
Locations string `thrift:"Locations,3" form:"Locations" json:"Locations" query:"Locations"`
|
||||
CurrentConditions string `thrift:"CurrentConditions,4" form:"CurrentConditions" json:"CurrentConditions" query:"CurrentConditions"`
|
||||
DailyForecasts string `thrift:"DailyForecasts,5" form:"DailyForecasts" json:"DailyForecasts" query:"DailyForecasts"`
|
||||
}
|
||||
|
||||
func NewQueryResp() *QueryResp {
|
||||
|
|
@ -290,17 +288,12 @@ func (p *QueryResp) GetDailyForecasts() (v string) {
|
|||
return p.DailyForecasts
|
||||
}
|
||||
|
||||
func (p *QueryResp) GetEarthquakeInformations() (v string) {
|
||||
return p.EarthquakeInformations
|
||||
}
|
||||
|
||||
var fieldIDToName_QueryResp = map[int16]string{
|
||||
1: "Code",
|
||||
2: "LocationKey",
|
||||
3: "Locations",
|
||||
4: "CurrentConditions",
|
||||
5: "DailyForecasts",
|
||||
6: "EarthquakeInformations",
|
||||
}
|
||||
|
||||
func (p *QueryResp) Read(iprot thrift.TProtocol) (err error) {
|
||||
|
|
@ -362,14 +355,6 @@ func (p *QueryResp) Read(iprot thrift.TProtocol) (err error) {
|
|||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
case 6:
|
||||
if fieldTypeId == thrift.STRING {
|
||||
if err = p.ReadField6(iprot); err != nil {
|
||||
goto ReadFieldError
|
||||
}
|
||||
} else if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
}
|
||||
default:
|
||||
if err = iprot.Skip(fieldTypeId); err != nil {
|
||||
goto SkipFieldError
|
||||
|
|
@ -454,17 +439,6 @@ func (p *QueryResp) ReadField5(iprot thrift.TProtocol) error {
|
|||
p.DailyForecasts = _field
|
||||
return nil
|
||||
}
|
||||
func (p *QueryResp) ReadField6(iprot thrift.TProtocol) error {
|
||||
|
||||
var _field string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
_field = v
|
||||
}
|
||||
p.EarthquakeInformations = _field
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *QueryResp) Write(oprot thrift.TProtocol) (err error) {
|
||||
|
||||
|
|
@ -493,10 +467,6 @@ func (p *QueryResp) Write(oprot thrift.TProtocol) (err error) {
|
|||
fieldId = 5
|
||||
goto WriteFieldError
|
||||
}
|
||||
if err = p.writeField6(oprot); err != nil {
|
||||
fieldId = 6
|
||||
goto WriteFieldError
|
||||
}
|
||||
}
|
||||
if err = oprot.WriteFieldStop(); err != nil {
|
||||
goto WriteFieldStopError
|
||||
|
|
@ -600,23 +570,6 @@ WriteFieldEndError:
|
|||
return thrift.PrependError(fmt.Sprintf("%T write field 5 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *QueryResp) writeField6(oprot thrift.TProtocol) (err error) {
|
||||
if err = oprot.WriteFieldBegin("EarthquakeInformations", thrift.STRING, 6); err != nil {
|
||||
goto WriteFieldBeginError
|
||||
}
|
||||
if err := oprot.WriteString(p.EarthquakeInformations); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = oprot.WriteFieldEnd(); err != nil {
|
||||
goto WriteFieldEndError
|
||||
}
|
||||
return nil
|
||||
WriteFieldBeginError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 6 begin error: ", p), err)
|
||||
WriteFieldEndError:
|
||||
return thrift.PrependError(fmt.Sprintf("%T write field 6 end error: ", p), err)
|
||||
}
|
||||
|
||||
func (p *QueryResp) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
app_secrets:
|
||||
- id: weatherQuery
|
||||
- id: weatherQuery1
|
||||
secret: secret1
|
||||
- id: weatherQuery2
|
||||
secret: secret2
|
||||
- id: weatherQuery3
|
||||
secret: secret3
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
package biz
|
||||
|
||||
var _earthquakeInfo string
|
||||
|
||||
func GetEarthquakeInfo() string {
|
||||
return _earthquakeInfo
|
||||
}
|
||||
|
|
@ -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