This commit is contained in:
Zheng Kai
2023-03-30 16:41:44 +08:00
parent 049277f1f6
commit af429a393a
13 changed files with 155 additions and 29 deletions

View File

@@ -2,7 +2,9 @@ package core
import (
"fmt"
"net/http"
"project/pb"
"project/util"
"project/zj"
"sync"
"time"
@@ -10,6 +12,7 @@ import (
type row struct {
hash [16]byte
hr *http.Request
req *pb.Req
rsp []byte
err error
@@ -25,7 +28,10 @@ func (pr *row) run() {
s := fmt.Sprintf(`%x, %s`, pr.hash, pr.t.Format(`2006-01-02 15:04:05`))
zj.J(`new`, s)
pr.rsp = []byte(s)
pr.rsp, pr.err = fetchRemote(pr.req)
go pr.saveFile()
go pr.metrics()
pr.done = true
pr.mux.Unlock()
}
@@ -36,3 +42,14 @@ func (pr *row) wait() {
pr.mux.RUnlock()
}
}
func (pr *row) saveFile() {
rspFile := util.CacheName(pr.req.Hash()) + `-rsp.json`
if !util.FileExists(rspFile) {
util.WriteFile(rspFile, pr.rsp)
zj.J(rspFile)
}
}
func (pr *row) metrics() {
}