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.

91 lines
2.1 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
9 years ago
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "net"
  7. "net/http"
  8. "os"
  9. "regexp"
  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. metaDir string
  18. noLogs bool
  19. siteName string
  20. siteURL string
  21. }
  22. func main() {
  23. flag.StringVar(&Config.bind, "b", "127.0.0.1:8080",
  24. "host to bind to (default: 127.0.0.1:8080)")
  25. flag.StringVar(&Config.filesDir, "filespath", "files/",
  26. "path to files directory")
  27. flag.StringVar(&Config.metaDir, "metapath", "meta/",
  28. "path to metadata directory")
  29. flag.BoolVar(&Config.noLogs, "nologs", false,
  30. "remove stdout output for each request")
  31. flag.StringVar(&Config.siteName, "sitename", "linx",
  32. "name of the site")
  33. flag.StringVar(&Config.siteURL, "siteurl", "http://"+Config.bind+"/",
  34. "site base url")
  35. flag.Parse()
  36. if Config.noLogs {
  37. goji.Abandon(middleware.Logger)
  38. }
  39. // make directories if needed
  40. var err error
  41. err = os.MkdirAll(Config.filesDir, 0755)
  42. if err != nil {
  43. fmt.Printf("Error: could not create files directory\n")
  44. os.Exit(1)
  45. }
  46. err = os.MkdirAll(Config.metaDir, 0700)
  47. if err != nil {
  48. fmt.Printf("Error: could not create metadata directory\n")
  49. os.Exit(1)
  50. }
  51. // ensure siteURL ends wth '/'
  52. if lastChar := Config.siteURL[len(Config.siteURL)-1:]; lastChar != "/" {
  53. Config.siteURL = Config.siteURL + "/"
  54. }
  55. // Template Globals
  56. pongo2.DefaultSet.Globals["sitename"] = Config.siteName
  57. // Routing setup
  58. nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
  59. selifRe := regexp.MustCompile(`^/selif/(?P<name>[a-z0-9-\.]+)$`)
  60. goji.Get("/", indexHandler)
  61. goji.Post("/upload", uploadPostHandler)
  62. goji.Post("/upload/", http.RedirectHandler("/upload", 301))
  63. goji.Put("/upload", uploadPutHandler)
  64. goji.Put("/upload/:name", uploadPutHandler)
  65. goji.Get("/static/*", http.StripPrefix("/static/",
  66. http.FileServer(http.Dir("static/"))))
  67. goji.Get(nameRe, fileDisplayHandler)
  68. goji.Get(selifRe, fileServeHandler)
  69. goji.NotFound(notFoundHandler)
  70. listener, err := net.Listen("tcp", Config.bind)
  71. if err != nil {
  72. log.Fatal("Could not bind: ", err)
  73. }
  74. goji.ServeListener(listener)
  75. }