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.

47 lines
1.0 KiB

9 years ago
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "net"
  7. "net/http"
  8. "regexp"
  9. "github.com/zenazn/goji"
  10. // "github.com/zenazn/goji/web"
  11. )
  12. var Config struct {
  13. bind string
  14. filesDir string
  15. siteName 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, "d", "files/",
  21. "path to files directory (default: files/)")
  22. flag.StringVar(&Config.siteName, "n", "linx",
  23. "name of the site")
  24. flag.Parse()
  25. fmt.Printf("About to listen on http://%s\n", Config.bind)
  26. nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
  27. selifRe := regexp.MustCompile(`^/selif/(?P<name>[a-z0-9-\.]+)$`)
  28. goji.Get("/", indexHandler)
  29. goji.Post("/upload", uploadPostHandler)
  30. goji.Put("/upload", uploadPutHandler)
  31. goji.Get(nameRe, fileDisplayHandler)
  32. goji.Handle(selifRe, http.StripPrefix("/selif/", http.FileServer(http.Dir(Config.filesDir))))
  33. listener, err := net.Listen("tcp", Config.bind)
  34. if err != nil {
  35. log.Fatal("Could not bind: ", err)
  36. }
  37. goji.ServeListener(listener)
  38. }