This commit is contained in:
zhaoxiaorong 2025-04-11 17:44:49 +08:00
parent 04b8e5b03b
commit 50c23df124
2 changed files with 25 additions and 2 deletions

View File

@ -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)

18
oplog/types.go Normal file
View File

@ -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"
)