Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor apis #129

Merged
merged 3 commits into from Mar 28, 2020
Merged

refactor apis #129

merged 3 commits into from Mar 28, 2020

Conversation

zhulijian1
Copy link
Contributor

@zhulijian1 zhulijian1 commented Mar 26, 2020

修改原因:
Fixes #130

修改内容:
重构kv相关API,包括:

  • 新增POST接口 POST /kv 传body体,若已存在则返回409错误,不会更新
  • put API 不再兼容,旧API /kv/{key}删除,改为新的/kv/{kv_id}。 body传可更改的就可以了,目前可更改的只有status和value。若kv_id不存在则返回404,不会新增
  • 变更 DELETE由/kv?kv_id={kv_id} 改为 /kv/{kv_id}
  • 新增 GET /kv/{kv_id}, 原/kv/{key}通过/kv?key={key}实现

修改后查询有两种方式:
一种: GET /kv/{kv_id} 通过kv_id查询唯一kv,查不到返回404,立即返回,不支持watch。
另一种: GET /kv?key={key}&label=xxxx... 查询符合条件的kv List,与原来API的/kv/{key}?label=xxxx...功能一致,只是参数key从path中移到了query中。查不到返回是200。支持watch。

Signed-off-by: zhulijian <zhulijian1@huawei.com>
docs/api.yaml Outdated Show resolved Hide resolved
server/resource/v1/history_resource.go Outdated Show resolved Hide resolved
if err != nil {
openlogging.Error(fmt.Sprintf("post [%v] err:%s", kvDoc, err.Error()))
if err == session.ErrKVAlreadyExists {
WriteErrResponse(context, http.StatusConflict, err.Error(), common.ContentTypeText)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WriteErrResponse这个函数以前写的有问题,MIME其实应该写死json

server/resource/v1/kv_resource.go Outdated Show resolved Hide resolved
server/resource/v1/kv_resource.go Outdated Show resolved Hide resolved
@@ -43,11 +43,13 @@ var (
//KV provide api of KV entity
type KV interface {
//below 3 methods is usually for admin console
Create(ctx context.Context, kv *model.KVDoc) (*model.KVDoc, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议保持createorupdate语义,简洁,内部只需要小改动,而且你不用改UT了

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不太好搞,算了

@tianxiaoliang
Copy link
Contributor

resource层UT别忘了改

@zhulijian1 zhulijian1 force-pushed the refactor branch 2 times, most recently from 5a3b59f to ed2a1e4 Compare March 27, 2020 07:50
docs/api.yaml Outdated Show resolved Hide resolved
docs/api.yaml Show resolved Hide resolved
server/resource/v1/kv_resource.go Outdated Show resolved Hide resolved
Signed-off-by: zhulijian <zhulijian1@huawei.com>
@zhulijian1 zhulijian1 changed the title wip: refactor apis refactor apis Mar 27, 2020
@tianxiaoliang tianxiaoliang merged commit 80dc785 into apache:master Mar 28, 2020
@zhulijian1 zhulijian1 deleted the refactor branch March 28, 2020 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

部分API不太符合restful的规范
2 participants