diff options
author | 2021-06-21 21:08:02 +0200 | |
---|---|---|
committer | 2021-06-21 21:08:02 +0200 | |
commit | 5a2f3b35baeacff0c88c4455897f5edef9e6190f (patch) | |
tree | b0cde002b58545275d7010051200ae754c2e57dd /internal/router/router.go | |
parent | add favicon (#54) (diff) | |
download | gotosocial-5a2f3b35baeacff0c88c4455897f5edef9e6190f.tar.xz |
add 404 handler (#57)
Diffstat (limited to 'internal/router/router.go')
-rw-r--r-- | internal/router/router.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/internal/router/router.go b/internal/router/router.go index e575b112f..1b8d899fa 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -42,6 +42,8 @@ type Router interface { AttachHandler(method string, path string, f gin.HandlerFunc) // Attach a gin middleware to the router that will be used globally AttachMiddleware(handler gin.HandlerFunc) + // Attach 404 NoRoute handler + AttachNoRouteHandler(handler gin.HandlerFunc) // Start the router Start() // Stop the router @@ -109,6 +111,11 @@ func (r *router) AttachMiddleware(middleware gin.HandlerFunc) { r.engine.Use(middleware) } +// AttachNoRouteHandler attaches a gin.HandlerFunc to NoRoute to handle 404's +func (r *router) AttachNoRouteHandler(handler gin.HandlerFunc) { + r.engine.NoRoute(handler) +} + // New returns a new Router with the specified configuration, using the given logrus logger. func New(config *config.Config, logger *logrus.Logger) (Router, error) { lvl, err := logrus.ParseLevel(config.LogLevel) |