blob: 1416d078e7379d6de81ac22c2755d1f789ae0c30 [file] [log] [blame]
package main
import (
"flag"
"fmt"
"mime"
"net/http"
"strings"
"github.com/golang/glog"
"code.hackerspace.pl/hscloud/hswaw/cebulacamp/landing/static"
)
var (
flagBind string
)
func init() {
flag.Set("logtostderr", "true")
}
func main() {
flag.StringVar(&flagBind, "bind", "0.0.0.0:8080", "Address at which to serve HTTP requests")
flag.Parse()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if path == "/" {
path = "/index.html"
}
path = strings.TrimPrefix(path, "/")
staticPath := fmt.Sprintf("hswaw/cebulacamp/landing/%s", path)
if data, ok := static.Data[staticPath]; ok {
parts := strings.Split(path, ".")
ext := fmt.Sprintf(".%s", parts[len(parts)-1])
t := mime.TypeByExtension(ext)
w.Header().Set("Content-Type", t)
w.Write(data)
} else {
http.NotFound(w, r)
}
})
glog.Infof("Starting up at %v", flagBind)
err := http.ListenAndServe(flagBind, nil)
if err != nil {
glog.Exit(err)
}
}