middleware/timeout: add timeout middleware
This commit is contained in:
parent
9f83bc7b58
commit
14af16c71e
11
framework/middleware/timeout.go
Normal file
11
framework/middleware/timeout.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.vinchent.xyz/vinchent/go-web/framework"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Timeout(d time.Duration) framework.ControllerHandler {
|
||||||
|
return func(c *framework.Context) error { return nil }
|
||||||
|
}
|
25
framework/middleware/timeout_test.go
Normal file
25
framework/middleware/timeout_test.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package middleware
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.vinchent.xyz/vinchent/go-web/framework"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTimeout(t *testing.T) {
|
||||||
|
t.Run("Test timeout handler", func(t *testing.T) {
|
||||||
|
timeoutHandler := Timeout(1 * time.Millisecond)
|
||||||
|
|
||||||
|
request := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||||
|
response := httptest.NewRecorder()
|
||||||
|
c := framework.NewContext(response, request)
|
||||||
|
|
||||||
|
err := timeoutHandler(c)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user