Contains the Concourse pipeline definition for building a line-server container
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
688 B

  1. package main
  2. import (
  3. "net/http"
  4. "os"
  5. "path"
  6. "github.com/zenazn/goji/web"
  7. )
  8. func fileServeHandler(c web.C, w http.ResponseWriter, r *http.Request) {
  9. fileName := c.URLParams["name"]
  10. filePath := path.Join(Config.filesDir, fileName)
  11. if !fileExistsAndNotExpired(fileName) {
  12. notFoundHandler(c, w, r)
  13. return
  14. }
  15. http.ServeFile(w, r, filePath)
  16. }
  17. func fileExistsAndNotExpired(filename string) bool {
  18. filePath := path.Join(Config.filesDir, filename)
  19. _, err := os.Stat(filePath)
  20. if err != nil {
  21. return false
  22. }
  23. if isFileExpired(filename) {
  24. os.Remove(path.Join(Config.filesDir, filename))
  25. os.Remove(path.Join(Config.metaDir, filename))
  26. return false
  27. }
  28. return true
  29. }