handling context timeout/cancelled in printer package

This commit is contained in:
Julien Neuhart
2019-07-09 19:39:14 +02:00
parent 957b9b1cf4
commit c7ecdcf625
9 changed files with 81 additions and 61 deletions

View File

@@ -1,6 +1,7 @@
package context
import (
"fmt"
"net/http"
"strconv"
"time"
@@ -35,9 +36,10 @@ func New(c echo.Context, logger *logger.Logger, config *config.Config) *Context
// MustCastFromEchoContext cast an echo.Context to our custom
// context. If something goes wrong, panic.
func MustCastFromEchoContext(c echo.Context) *Context {
const op = "MustCastFromEchoContext"
ctx, ok := c.(*Context)
if !ok {
panic("unable to cast an echo.Context to a custom context")
panic(fmt.Sprintf("%s: unable to cast an echo.Context to a custom context", op))
}
return ctx
}