Micro & pluggable web framework for Go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
496B

  1. // Copyright 2015 The Tango Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package tango
  5. import (
  6. "strings"
  7. )
  8. // Prefix provides a middleware to wrap another middleware with a prefix URL
  9. // TODO: regex prefix
  10. func Prefix(prefix string, handler Handler) HandlerFunc {
  11. return func(ctx *Context) {
  12. if strings.HasPrefix(ctx.Req().URL.Path, prefix) {
  13. handler.Handle(ctx)
  14. return
  15. }
  16. ctx.Next()
  17. }
  18. }