Skip to content

Commit

Permalink
fix param split bug
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhao committed Aug 26, 2019
1 parent 3cc836c commit 348f61e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

##### Version 1.1.2
1. fix no LatestTimestamp when register
2. update go mod
2. fix param split bug
3. update go mod

##### Version 1.1.1
1. fix initproject abort
Expand Down
4 changes: 2 additions & 2 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ GET http://HOST/discovery/polls
| appid | true | []string | 服务名标识 |
| env | true | string | 环境 |
| zone | false | string | 可用区,不传返回所有zone的 |
| latest_timestamp | false | int | 服务最新更新时间 |
| latest_timestamp | false | []int | 服务最新更新时间,要与appid一一对应 |

*返回结果*

Expand Down Expand Up @@ -431,7 +431,7 @@ GET http://HOST/discovery/polls

*CURL*
```shell
curl 'http://127.0.0.1:7171/discovery/polls?zone=sh1&env=test&appid=provider&appid=provider2&latest_timestamp=0'
curl 'http://127.0.0.1:7171/discovery/polls?zone=sh1&env=test&appid=provider1&appid=provider2&latest_timestamp=01&latest_timestamp=02'
```

### 获取node节点
Expand Down
14 changes: 7 additions & 7 deletions model/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type ArgRegister struct {
AppID string `form:"appid" validate:"required"`
Hostname string `form:"hostname" validate:"required"`
Status uint32 `form:"status" validate:"required"`
Addrs []string `form:"addrs,split" validate:"gt=0"`
Addrs []string `form:"addrs" validate:"gt=0"`
Version string `form:"version"`
Metadata string `form:"metadata"`
Replication bool `form:"replication"`
Expand Down Expand Up @@ -51,7 +51,7 @@ type ArgFetch struct {
type ArgFetchs struct {
Zone string `form:"zone"`
Env string `form:"env" validate:"required"`
AppID []string `form:"appid,split" validate:"gt=0"`
AppID []string `form:"appid" validate:"gt=0"`
Status uint32 `form:"status" validate:"required"`
}

Expand All @@ -68,9 +68,9 @@ type ArgPoll struct {
type ArgPolls struct {
Zone string `form:"zone"`
Env string `form:"env" validate:"required"`
AppID []string `form:"appid,split" validate:"gt=0"`
AppID []string `form:"appid" validate:"gt=0"`
Hostname string `form:"hostname" validate:"required"`
LatestTimestamp []int64 `form:"latest_timestamp,split"`
LatestTimestamp []int64 `form:"latest_timestamp"`
}

// ArgSet define set param.
Expand All @@ -79,9 +79,9 @@ type ArgSet struct {
Zone string `form:"zone" validate:"required"`
Env string `form:"env" validate:"required"`
AppID string `form:"appid" validate:"required"`
Hostname []string `form:"hostname,split" validate:"gte=0"`
Status []int64 `form:"status,split" validate:"gte=0"`
Metadata []string `form:"metadata" validate:"gte=0"` // metadata may contain `,` , use metadata=xx&metadata=xx instead of split by ','
Hostname []string `form:"hostname" validate:"gte=0"`
Status []int64 `form:"status" validate:"gte=0"`
Metadata []string `form:"metadata" validate:"gte=0"`
Replication bool `form:"replication"`
FromZone bool `form:"from_zone"`
SetTimestamp int64 `form:"set_timestamp"`
Expand Down
15 changes: 10 additions & 5 deletions naming/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (
"math/rand"
"net/url"
"os"
"strings"
"strconv"
"sync"
"sync/atomic"
"time"

ecode "github.com/bilibili/kratos/pkg/ecode"
log "github.com/bilibili/kratos/pkg/log"
http "github.com/bilibili/kratos/pkg/net/http/blademaster"
xstr "github.com/bilibili/kratos/pkg/str"
xtime "github.com/bilibili/kratos/pkg/time"
)

Expand Down Expand Up @@ -335,7 +334,9 @@ func (d *Discovery) register(ctx context.Context, ins *Instance) (err error) {
uri := fmt.Sprintf(_registerURL, d.pickNode())
params := d.newParams(c)
params.Set("appid", ins.AppID)
params.Set("addrs", strings.Join(ins.Addrs, ","))
for _, addr := range ins.Addrs {
params.Add("addrs", addr)
}
params.Set("version", ins.Version)
params.Set("status", _statusUP)
params.Set("metadata", string(metadata))
Expand Down Expand Up @@ -541,8 +542,12 @@ func (d *Discovery) polls(ctx context.Context) (apps map[string]*InstancesInfo,
params := url.Values{}
params.Set("env", c.Env)
params.Set("hostname", c.Host)
params.Set("appid", strings.Join(appIDs, ","))
params.Set("latest_timestamp", xstr.JoinInts(lastTss))
for _, appid := range appIDs {
params.Add("appid", appid)
}
for _, ts := range lastTss {
params.Add("latest_timestamp", strconv.FormatInt(ts, 10))
}
if err = d.httpClient.Get(ctx, uri, "", params, res); err != nil {
d.switchNode()
if ctx.Err() != context.Canceled {
Expand Down

0 comments on commit 348f61e

Please sign in to comment.