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

#79 record polling history #90

Closed
wants to merge 10 commits into from
Closed

Conversation

GuoYL123
Copy link
Contributor

No description provided.

@GuoYL123 GuoYL123 closed this Feb 11, 2020
@GuoYL123 GuoYL123 reopened this Feb 11, 2020
@GuoYL123 GuoYL123 changed the title record polling history #79 record polling history Feb 11, 2020
server/resource/v1/common.go Outdated Show resolved Hide resolved
server/resource/v1/kv_resource.go Outdated Show resolved Hide resolved
server/service/mongo/record/polling_detail_dao.go Outdated Show resolved Hide resolved
server/resource/v1/kv_resource.go Outdated Show resolved Hide resolved
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)
Copy link
Contributor

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())
Copy link
Contributor

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"
Copy link
Contributor

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"
Copy link
Contributor

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"`
Copy link
Contributor

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"`
Copy link
Contributor

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 {
Copy link
Contributor

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)
Copy link
Contributor

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) {
Copy link
Contributor

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, "", "")
Copy link
Contributor

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

改参数名

@GuoYL123 GuoYL123 closed this Feb 13, 2020
@GuoYL123 GuoYL123 deleted the record-new branch February 17, 2020 09:11
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.

None yet

2 participants