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.

56 lines
1.4 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
  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. )
  11. var Config struct {
  12. bind string
  13. filesDir string
  14. siteName string
  15. siteURL string
  16. }
  17. func main() {
  18. flag.StringVar(&Config.bind, "b", "127.0.0.1:8080",
  19. "host to bind to (default: 127.0.0.1:8080)")
  20. flag.StringVar(&Config.filesDir, "filespath", "files/",
  21. "path to files directory (default: files/)")
  22. flag.StringVar(&Config.siteName, "sitename", "linx",
  23. "name of the site")
  24. flag.StringVar(&Config.siteURL, "siteurl", "http://"+Config.bind+"/",
  25. "site base url (including trailing slash)")
  26. flag.Parse()
  27. // Disable template caching -- keep until out of pre-alpha
  28. pongo2.DefaultSet.Debug = true // will keep this until out of pre-alpha
  29. // Template Globals
  30. pongo2.DefaultSet.Globals["sitename"] = Config.siteName
  31. // Routing setup
  32. nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
  33. selifRe := regexp.MustCompile(`^/selif/(?P<name>[a-z0-9-\.]+)$`)
  34. goji.Get("/", indexHandler)
  35. goji.Post("/upload", uploadPostHandler)
  36. goji.Put("/upload", uploadPutHandler)
  37. goji.Get("/static/*", http.StripPrefix("/static/",
  38. http.FileServer(http.Dir("static/"))))
  39. goji.Get(nameRe, fileDisplayHandler)
  40. goji.Get(selifRe, fileServeHandler)
  41. listener, err := net.Listen("tcp", Config.bind)
  42. if err != nil {
  43. log.Fatal("Could not bind: ", err)
  44. }
  45. goji.ServeListener(listener)
  46. }