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.

46 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. )
  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. fmt.Printf("About to listen on http://%s\n", Config.bind)
  25. nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
  26. selifRe := regexp.MustCompile(`^/selif/(?P<name>[a-z0-9-\.]+)$`)
  27. goji.Get("/", indexHandler)
  28. goji.Post("/upload", uploadPostHandler)
  29. goji.Put("/upload", uploadPutHandler)
  30. goji.Get(nameRe, fileDisplayHandler)
  31. goji.Handle(selifRe, http.StripPrefix("/selif/", http.FileServer(http.Dir(Config.filesDir))))
  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. }