Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deadline ¶
Deadline return a time corrector.
It useful for go.octolab.org/toolkit/protocol/http/header.Deadline and go.octolab.org/toolkit/protocol/http/middleware.Deadline.
mux := http.NewServeMux() sla := middleware.Deadline(time.Second, timer.Deadline(0.95, time.Millisecond)) handler := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}) mux.Handle("/", sla(handler)) log.Fatal(http.ListenAndServe(":80", mux))
It also useful for the built-in context package.
func(rw http.ResponseWriter, req *http.Request) { ctx := req.Context() corrector := timer.Deadline(0.95, time.Millisecond) ctx, cancel := context.WithDeadline(req.Context(), corrector(ctx.Deadline())) defer cancel() select { case <-ctx.Done(): message := http.StatusText(http.StatusRequestTimeout) http.Error(rw, message, http.StatusRequestTimeout) case result := <-rpc.Call(ctx): unsafe.Ignore(json.NewEncoder(rw).Encode(result)) } }
func Stopwatch ¶ added in v0.0.14
Stopwatch calculates the fn execution time.
var result interface{} duration := fn.Stopwatch(func() { result = do.some("heavy") })
func Timeout ¶
Timeout return a duration corrector.
It useful for go.octolab.org/toolkit/protocol/http/header.Timeout and go.octolab.org/toolkit/protocol/http/middleware.Timeout.
mux := http.NewServeMux() sla := middleware.Timeout(time.Second, timer.Timeout(0.95, time.Millisecond)) handler := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}) mux.Handle("/", sla(handler)) log.Fatal(http.ListenAndServe(":80", mux))
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.