2015-09-24 07:44:49 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"github.com/zenazn/goji"
|
|
|
|
)
|
|
|
|
|
|
|
|
var Config struct {
|
|
|
|
bind string
|
|
|
|
filesDir string
|
|
|
|
siteName string
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.StringVar(&Config.bind, "b", "127.0.0.1:8080",
|
|
|
|
"host to bind to (default: 127.0.0.1:8080)")
|
|
|
|
flag.StringVar(&Config.filesDir, "d", "files/",
|
|
|
|
"path to files directory (default: files/)")
|
|
|
|
flag.StringVar(&Config.siteName, "n", "linx",
|
|
|
|
"name of the site")
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
nameRe := regexp.MustCompile(`^/(?P<name>[a-z0-9-\.]+)$`)
|
|
|
|
selifRe := regexp.MustCompile(`^/selif/(?P<name>[a-z0-9-\.]+)$`)
|
|
|
|
|
|
|
|
goji.Get("/", indexHandler)
|
|
|
|
goji.Post("/upload", uploadPostHandler)
|
|
|
|
goji.Put("/upload", uploadPutHandler)
|
2015-09-24 22:04:51 +02:00
|
|
|
goji.Get("/static/*", http.StripPrefix("/static/",
|
|
|
|
http.FileServer(http.Dir("static/"))))
|
2015-09-24 07:44:49 +02:00
|
|
|
goji.Get(nameRe, fileDisplayHandler)
|
2015-09-24 22:04:51 +02:00
|
|
|
goji.Get(selifRe, fileServeHandler)
|
2015-09-24 07:44:49 +02:00
|
|
|
|
|
|
|
listener, err := net.Listen("tcp", Config.bind)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Could not bind: ", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
goji.ServeListener(listener)
|
|
|
|
}
|