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
#79 record polling history #90
Conversation
# Conflicts: # server/resource/v1/kv_resource.go
return | ||
} | ||
rctx.ReadResponseWriter().Header().Set(common.HeaderRevision, strconv.FormatInt(rev, 10)) | ||
err = writeResponse(rctx, kv) | ||
if err != nil { | ||
openlogging.Error(err.Error()) | ||
} | ||
respData, _ := json.Marshal(kv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不需要序列化,直接存数据
return | ||
} | ||
rctx.ReadResponseWriter().Header().Set(common.HeaderRevision, strconv.FormatInt(rev, 10)) | ||
err = writeResponse(rctx, kv) | ||
if err != nil { | ||
openlogging.Error(err.Error()) | ||
} | ||
respData, _ := json.Marshal(kv) | ||
respHeader, _ := json.Marshal(rctx.Resp.Header()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要序列化直接存map
bsonType: "string" | ||
}, | ||
response_body: { | ||
bsonType: "string" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不应该是个string应该是个bson object
bsonType: "string" | ||
}, | ||
response_header: { | ||
bsonType: "string" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不应该是个string应该是个bson object
IP string `json:"ip,omitempty" yaml:"ip,omitempty"` | ||
UserAgent string `json:"user_agent,omitempty" yaml:"user_agent,omitempty"` | ||
URLPath string `json:"url_path,omitempty" yaml:"url_path,omitempty"` | ||
ResponseBody string `json:"response_body,omitempty" yaml:"response_body,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResponseBody 用 struct
UserAgent string `json:"user_agent,omitempty" yaml:"user_agent,omitempty"` | ||
URLPath string `json:"url_path,omitempty" yaml:"url_path,omitempty"` | ||
ResponseBody string `json:"response_body,omitempty" yaml:"response_body,omitempty"` | ||
ResponseHeader string `json:"response_header,omitempty" yaml:"response_header,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ResponseHeader 用map[string][]string
@@ -64,6 +65,12 @@ type Label interface { | |||
CreateOrUpdate(ctx context.Context, label *model.LabelDoc) (*model.LabelDoc, error) | |||
} | |||
|
|||
//Record manages record data | |||
type Record interface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Record 就叫PollingRecorder
@@ -64,6 +65,12 @@ type Label interface { | |||
CreateOrUpdate(ctx context.Context, label *model.LabelDoc) (*model.LabelDoc, error) | |||
} | |||
|
|||
//Record manages record data | |||
type Record interface { | |||
RecordSuccess(ctx context.Context, detail *model.PollingDetail, respStatus int, respData, respHeader string) (*model.PollingDetail, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没必要搞2个func 合成一个,非必填参数用functional options
) | ||
|
||
//CreateOrUpdateRecord create a record or update exist record | ||
func CreateOrUpdateRecord(ctx context.Context, detail *model.PollingDetail) (*model.PollingDetail, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Record这个尾椎多余,要时刻考虑clean code,这里有上下文了
return | ||
} | ||
rctx.WriteHeader(http.StatusNotModified) | ||
return | ||
_, recordErr = service.RecordService.RecordSuccess(rctx.Ctx, recordData, http.StatusNotModified, "", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
太多地方需要考虑调用,不如用defer+一个func,虽然损失性能,但是优雅易维护
@@ -138,21 +141,24 @@ func (r *KVResource) List(rctx *restful.Context) { | |||
WriteErrResponse(rctx, http.StatusBadRequest, err.Error(), common.ContentTypeText) | |||
return | |||
} | |||
insID := rctx.ReadHeader("insId") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改参数名
No description provided.