tianxiaoliang commented on a change in pull request #108: #109 
client支持指定revision
URL: https://github.com/apache/servicecomb-kie/pull/108#discussion_r386241206
 
 

 ##########
 File path: client/client.go
 ##########
 @@ -158,31 +161,39 @@ func (c *Client) Get(ctx context.Context, opts 
...GetOption) (*model.KVResponse,
        h := http.Header{}
        resp, err := c.c.Do(ctx, http.MethodGet, url, h, nil)
        if err != nil {
-               return nil, err
+               return nil, -1, err
+       }
+       responseRevision, errRevision := 
strconv.Atoi(resp.Header.Get(common.HeaderRevision))
+       if errRevision != nil {
+               responseRevision = -1
        }
        b := httputil.ReadBody(resp)
        if resp.StatusCode != http.StatusOK {
                if resp.StatusCode == http.StatusNotFound {
-                       return nil, ErrKeyNotExist
+                       return nil, responseRevision, ErrKeyNotExist
                }
                if resp.StatusCode == http.StatusNotModified {
-                       return nil, ErrNoChanges
+                       return nil, responseRevision, ErrNoChanges
                }
                openlogging.Error(MsgGetFailed, 
openlogging.WithTags(openlogging.Tags{
                        "k":      options.Key,
                        "status": resp.Status,
                        "body":   b,
                }))
-               return nil, fmt.Errorf(FmtGetFailed, options.Key, resp.Status, 
b)
+               return nil, responseRevision, fmt.Errorf(FmtGetFailed, 
options.Key, resp.Status, b)
+       } else if errRevision != nil {
+               msg := fmt.Sprintf("get revision from response header failed 
when the request status is OK: %v", err)
+               openlogging.Error(msg)
+               return nil, responseRevision, fmt.Errorf(msg)
        }
        var kvs *model.KVResponse
        err = json.Unmarshal(b, &kvs)
        if err != nil {
                openlogging.Error("unmarshal kv failed:" + err.Error())
-               return nil, err
+               return nil, responseRevision, err
        }
-       c.CurrentRevision = resp.Header.Get(common.HeaderRevision)
-       return kvs, nil
+       c.currentRevision = responseRevision
+       return kvs, responseRevision, nil
 
 Review comment:
   调用者为何要关心这个responseRevision,你已经给了API专门用于拿当前revison了

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to