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.

38 lines
825B

  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. "net/http"
  7. "path/filepath"
  8. )
  9. // Content returns a handle to serve a file
  10. func Content(path string, fs http.FileSystem) func(ctx *Context) {
  11. return func(ctx *Context) {
  12. ctx.ServeContent(path, fs)
  13. }
  14. }
  15. // File returns a handle to serve a file
  16. func File(path string) func(ctx *Context) {
  17. return func(ctx *Context) {
  18. ctx.ServeFile(path)
  19. }
  20. }
  21. // Dir returns a handle to serve a directory
  22. func Dir(dir string) func(ctx *Context) {
  23. return func(ctx *Context) {
  24. params := ctx.Params()
  25. if len(*params) <= 0 {
  26. ctx.Result = NotFound()
  27. ctx.HandleError()
  28. return
  29. }
  30. ctx.ServeFile(filepath.Join(dir, (*params)[0].Value))
  31. }
  32. }