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.

53 lines
1.2 KiB

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