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.

68 lines
1.6 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package main
  2. import (
  3. "flag"
  4. "log"
  5. "net"
  6. "net/http"
  7. "regexp"
  8. "github.com/flosch/pongo2"
  9. "github.com/zenazn/goji"
  10. "github.com/zenazn/goji/web/middleware"
  11. )
  12. var Config struct {
  13. bind string
  14. filesDir string
  15. noLogs bool
  16. siteName string
  17. siteURL string
  18. }
  19. func main() {
  20. flag.StringVar(&Config.bind, "b", "127.0.0.1:8080",
  21. "host to bind to (default: 127.0.0.1:8080)")
  22. flag.StringVar(&Config.filesDir, "filespath", "files/",
  23. "path to files directory (including trailing slash)")
  24. flag.BoolVar(&Config.noLogs, "nologs", false,
  25. "remove stdout output for each request")
  26. flag.StringVar(&Config.siteName, "sitename", "linx",
  27. "name of the site")
  28. flag.StringVar(&Config.siteURL, "siteurl", "http://"+Config.bind+"/",
  29. "site base url (including trailing slash)")
  30. flag.Parse()
  31. if Config.noLogs {
  32. goji.Abandon(middleware.Logger)
  33. }
  34. // check trailing slashes
  35. // Template Globals
  36. pongo2.DefaultSet.Globals["sitename"] = Config.siteName
  37. // Routing setup
  38. nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
  39. selifRe := regexp.MustCompile(`^/selif/(?P<name>[a-z0-9-\.]+)$`)
  40. goji.Get("/", indexHandler)
  41. goji.Post("/upload", uploadPostHandler)
  42. goji.Post("/upload/", http.RedirectHandler("/upload", 301))
  43. goji.Put("/upload", uploadPutHandler)
  44. goji.Put("/upload/:name", uploadPutHandler)
  45. goji.Get("/static/*", http.StripPrefix("/static/",
  46. http.FileServer(http.Dir("static/"))))
  47. goji.Get(nameRe, fileDisplayHandler)
  48. goji.Get(selifRe, fileServeHandler)
  49. goji.NotFound(notFoundHandler)
  50. listener, err := net.Listen("tcp", Config.bind)
  51. if err != nil {
  52. log.Fatal("Could not bind: ", err)
  53. }
  54. goji.ServeListener(listener)
  55. }