Commit ce03c31b by huangchengyi

test

parent 4edd7d85
Showing with 9 additions and 4 deletions
package main package main
import ( import (
"github.com/syyongx/php2go"
"net/http" "net/http"
"time" "time"
...@@ -9,9 +10,13 @@ import ( ...@@ -9,9 +10,13 @@ import (
) )
func emptySuccessResponse(c *gin.Context) { func emptySuccessResponse(c *gin.Context) {
i := 2 if php2go.Rand(1,2) == 1 {
time.Sleep(i * time.Second) time.Sleep(1 * time.Second)
c.String(http.StatusOK, "") }else{
time.Sleep(2 * time.Second)
}
c.String(http.StatusOK, "成功-往下走")
} }
func errorResponse(c *gin.Context) { func errorResponse(c *gin.Context) {
c.String(http.StatusRequestTimeout, "超时") c.String(http.StatusRequestTimeout, "超时")
...@@ -21,7 +26,7 @@ func main() { ...@@ -21,7 +26,7 @@ func main() {
r := gin.New() r := gin.New()
r.GET("/", timeout.New( r.GET("/", timeout.New(
timeout.WithTimeout(100*time.Microsecond), timeout.WithTimeout(2*time.Second),
timeout.WithHandler(emptySuccessResponse), timeout.WithHandler(emptySuccessResponse),
timeout.WithResponse(errorResponse), timeout.WithResponse(errorResponse),
)) ))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment