From 50c23df124f5705e4188e87b6b87d41b008d5ff0 Mon Sep 17 00:00:00 2001 From: zhaoxiaorong Date: Fri, 11 Apr 2025 17:44:49 +0800 Subject: [PATCH] fix --- oplog/{oplog.go => new.go} | 9 +++++++-- oplog/types.go | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) rename oplog/{oplog.go => new.go} (58%) create mode 100644 oplog/types.go diff --git a/oplog/oplog.go b/oplog/new.go similarity index 58% rename from oplog/oplog.go rename to oplog/new.go index 0c7b797..c0e5e72 100644 --- a/oplog/oplog.go +++ b/oplog/new.go @@ -6,16 +6,21 @@ import ( "net/http" ) -func PostLog(data any, path string) (resp *http.Response, err error) { +func New(endpoint string, data []*LogItem) error { + go PostLog(data, endpoint) + return nil +} +func PostLog(data []*LogItem, endpoint string) (resp *http.Response, err error) { jsonBytes, err := json.Marshal(data) if err != nil { return nil, err } - req, err := http.NewRequest("POST", path, bytes.NewBuffer(jsonBytes)) + req, err := http.NewRequest("POST", endpoint, bytes.NewBuffer(jsonBytes)) if err != nil { return nil, err } + req.Header.Set("Content-Type", "application/json") client := &http.Client{} resp, err = client.Do(req) diff --git a/oplog/types.go b/oplog/types.go new file mode 100644 index 0000000..1851c58 --- /dev/null +++ b/oplog/types.go @@ -0,0 +1,18 @@ +package oplog + +type LogItem struct { + OpID uint `json:"op_id"` + OpName string `json:"op_name"` + OpType string `json:"op_type"` + Text string `json:"text"` +} + +var ( + Type_Login string = "login" + Type_Logout string = "logout" + Type_Register string = "register" + Type_Update string = "update" + Type_Delete string = "delete" + Type_Query string = "query" + Type_Other string = "other" +)