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.

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