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.

66 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
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 (default: files/)")
  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. // Template Globals
  35. pongo2.DefaultSet.Globals["sitename"] = Config.siteName
  36. // Routing setup
  37. nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
  38. selifRe := regexp.MustCompile(`^/selif/(?P<name>[a-z0-9-\.]+)$`)
  39. goji.Get("/", indexHandler)
  40. goji.Post("/upload", uploadPostHandler)
  41. goji.Post("/upload/", http.RedirectHandler("/upload", 301))
  42. goji.Put("/upload", uploadPutHandler)
  43. goji.Put("/upload/:name", uploadPutHandler)
  44. goji.Get("/static/*", http.StripPrefix("/static/",
  45. http.FileServer(http.Dir("static/"))))
  46. goji.Get(nameRe, fileDisplayHandler)
  47. goji.Get(selifRe, fileServeHandler)
  48. goji.NotFound(notFoundHandler)
  49. listener, err := net.Listen("tcp", Config.bind)
  50. if err != nil {
  51. log.Fatal("Could not bind: ", err)
  52. }
  53. goji.ServeListener(listener)
  54. }