Browse Source

Updated.

develop
Mingcai SHEN 2 years ago
parent
commit
aa22050988
3 changed files with 11 additions and 7 deletions
  1. +5
    -4
      http.go
  2. +4
    -1
      main.go
  3. +2
    -2
      recog.go

+ 5
- 4
http.go View File

@ -13,9 +13,9 @@ var httpClient *http.Client
var fakeClient = false var fakeClient = false
func httpPost(url string, data interface{}) error { func httpPost(url string, data interface{}) error {
log.Println("httpPost:url>", url)
log.Println("-> POST", url)
if fakeClient { if fakeClient {
log.Println("httpPost:data> fake client ")
//log.Println("httpPost:data> fake client ")
return nil return nil
} }
if bs, e := json.Marshal(data); nil != e { if bs, e := json.Marshal(data); nil != e {
@ -30,6 +30,7 @@ func httpPost(url string, data interface{}) error {
} }
func httpGet(url string, resp interface{}) error { func httpGet(url string, resp interface{}) error {
log.Println("-> GET", url)
return nil return nil
} }
@ -37,8 +38,8 @@ func httpPostEx(url string, data interface{}, retries int) error {
var err error var err error
for i := 0; i < retries; i++ { for i := 0; i < retries; i++ {
if err = httpPost(url, data); nil != err { if err = httpPost(url, data); nil != err {
log.Println(">>>", err)
time.Sleep(3 * time.Second)
log.Println("-> >>", err)
time.Sleep(1 * time.Second)
} else { } else {
return nil return nil
} }

+ 4
- 1
main.go View File

@ -32,7 +32,10 @@ var serveCmd = &cobra.Command{
Short: "Run service", Short: "Run service",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
app := fiber.New() app := fiber.New()
app.Use(func(c *fiber.Ctx) error {
log.Println("<-", c.IP(), c.Method(), c.Request().URI())
return c.Next()
})
app.Get("/", func(c *fiber.Ctx) error { app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!") return c.SendString("Hello, World!")
}) })

+ 2
- 2
recog.go View File

@ -247,7 +247,7 @@ func pushException(url string, scene string, seq int64, tp int, desc string, img
if nil != img { if nil != img {
st.TestData.Image = encodeImage(img) st.TestData.Image = encodeImage(img)
} }
httpPostEx(url, st, 3)
httpPostEx(url, st, 2)
} }
func pushEvent(url string, scene string, seq int64, state string, img image.Image, vals ...int) error { func pushEvent(url string, scene string, seq int64, state string, img image.Image, vals ...int) error {
@ -276,7 +276,7 @@ func pushEvent(url string, scene string, seq int64, state string, img image.Imag
} }
} }
return httpPostEx(url, st, 3)
return httpPostEx(url, st, 2)
} }
func recogTaskProc(cmd *TestCommand) error { func recogTaskProc(cmd *TestCommand) error {

Loading…
Cancel
Save