1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-31 05:04:23 +03:00

Rename GeoPosition to GeoPos for consistency with Redis Server. Simplify code where possible.

This commit is contained in:
Vladimir Mihailenco
2016-08-22 09:39:22 +00:00
parent 5e72ba7620
commit 235dc49d5f
3 changed files with 45 additions and 47 deletions

View File

@ -273,46 +273,42 @@ func newGeoLocationSliceParser(q *GeoRadiusQuery) proto.MultiBulkParse {
}
}
func newGeoPositionParser() proto.MultiBulkParse {
return func(rd *proto.Reader, n int64) (interface{}, error) {
var pos GeoPosition
var err error
func geoPosParser(rd *proto.Reader, n int64) (interface{}, error) {
var pos GeoPos
var err error
pos.Longitude, err = rd.ReadFloatReply()
if err != nil {
return nil, err
}
pos.Latitude, err = rd.ReadFloatReply()
if err != nil {
return nil, err
}
return &pos, nil
pos.Longitude, err = rd.ReadFloatReply()
if err != nil {
return nil, err
}
pos.Latitude, err = rd.ReadFloatReply()
if err != nil {
return nil, err
}
return &pos, nil
}
func newGeoPositionSliceParser() proto.MultiBulkParse {
return func(rd *proto.Reader, n int64) (interface{}, error) {
positions := make([]*GeoPosition, 0, n)
for i := int64(0); i < n; i++ {
v, err := rd.ReadReply(newGeoPositionParser())
if err != nil {
// response may contain nil results
if err == Nil {
positions = append(positions, nil)
continue
}
return nil, err
}
switch vv := v.(type) {
case *GeoPosition:
positions = append(positions, vv)
default:
return nil, fmt.Errorf("got %T, expected *GeoPosition", v)
func geoPosSliceParser(rd *proto.Reader, n int64) (interface{}, error) {
positions := make([]*GeoPos, 0, n)
for i := int64(0); i < n; i++ {
v, err := rd.ReadReply(geoPosParser)
if err != nil {
if err == Nil {
positions = append(positions, nil)
continue
}
return nil, err
}
switch v := v.(type) {
case *GeoPos:
positions = append(positions, v)
default:
return nil, fmt.Errorf("got %T, expected *GeoPos", v)
}
return positions, nil
}
return positions, nil
}
func commandInfoParser(rd *proto.Reader, n int64) (interface{}, error) {