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.

45 lines
1008 B

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/zenazn/goji"
  9. )
  10. var Config struct {
  11. bind string
  12. filesDir string
  13. siteName string
  14. }
  15. func main() {
  16. flag.StringVar(&Config.bind, "b", "127.0.0.1:8080",
  17. "host to bind to (default: 127.0.0.1:8080)")
  18. flag.StringVar(&Config.filesDir, "d", "files/",
  19. "path to files directory (default: files/)")
  20. flag.StringVar(&Config.siteName, "n", "linx",
  21. "name of the site")
  22. flag.Parse()
  23. nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
  24. selifRe := regexp.MustCompile(`^/selif/(?P<name>[a-z0-9-\.]+)$`)
  25. goji.Get("/", indexHandler)
  26. goji.Post("/upload", uploadPostHandler)
  27. goji.Put("/upload", uploadPutHandler)
  28. goji.Get("/static/*", http.StripPrefix("/static/",
  29. http.FileServer(http.Dir("static/"))))
  30. goji.Get(nameRe, fileDisplayHandler)
  31. goji.Get(selifRe, fileServeHandler)
  32. listener, err := net.Listen("tcp", Config.bind)
  33. if err != nil {
  34. log.Fatal("Could not bind: ", err)
  35. }
  36. goji.ServeListener(listener)
  37. }