dev oplog
This commit is contained in:
parent
c08950c10a
commit
4b73f086b1
28
oplog/new.go
28
oplog/new.go
|
@ -1,32 +1,14 @@
|
||||||
package oplog
|
package oplog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
|
||||||
|
"git.apinb.com/bsm-sdk/core/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(endpoint string, data []*LogItem) error {
|
func New(endpoint string, data []*LogItem) {
|
||||||
go PostLog(data, endpoint)
|
jsonBytes, _ := json.Marshal(data)
|
||||||
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", endpoint, bytes.NewBuffer(jsonBytes))
|
go utils.HttpPost(endpoint, nil, jsonBytes)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Set("Content-Type", "application/json")
|
|
||||||
client := &http.Client{}
|
|
||||||
resp, err = client.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package oplog
|
package oplog
|
||||||
|
|
||||||
type LogRequest struct {
|
|
||||||
Data []*LogItem `json:"data"`
|
|
||||||
}
|
|
||||||
type LogItem struct {
|
type LogItem struct {
|
||||||
OpID uint `json:"op_id"`
|
OpID uint `json:"op_id"`
|
||||||
OpName string `json:"op_name"`
|
OpName string `json:"op_name"`
|
||||||
|
|
Loading…
Reference in New Issue