generate working static file

This commit is contained in:
sm
2015-04-20 23:18:40 -07:00
parent 325186b237
commit 96e4a101d8
4 changed files with 413 additions and 2 deletions
-1
View File
@@ -5,6 +5,5 @@ import (
)
var addr = flag.String("addr", ":8000", "http service address")
var static_files = flag.String("static", "./static", "location of static files")
var db_file = flag.String("db", "db.json", "output database")
var template_dir = flag.String("templates", "templates", "template dir")
+6
View File
@@ -0,0 +1,6 @@
package main
//go:generate go get github.com/jteeuwen/go-bindata/...
//go:generate go get github.com/elazarl/go-bindata-assetfs/...
//go:generate rm -f static.go
//go:generate go-bindata -o static.go -pkg=main static/...
+19 -1
View File
@@ -7,8 +7,11 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"sync"
"github.com/elazarl/go-bindata-assetfs"
)
type Cred struct {
@@ -47,8 +50,23 @@ func main() {
http.HandleFunc("/hello/", helloHandler)
http.HandleFunc("/pass", passHandler)
http.HandleFunc("/api/1.0/creds/", credHandler)
var fs http.FileSystem
if os.Getenv("DEV") == "" {
log.Printf("static: prod mode")
fs = &assetfs.AssetFS{
Asset: Asset,
AssetDir: AssetDir,
Prefix: "static",
}
} else {
log.Printf("static: dev mode")
fs = http.Dir(os.Getenv("DEV"))
}
http.Handle("/s/", http.StripPrefix("/s/",
http.FileServer(http.Dir(*static_files))))
http.FileServer(fs)))
if err := http.ListenAndServe(*addr, nil); err != nil {
log.Fatal("ListenAndServe:", err)
}
+388
View File
File diff suppressed because one or more lines are too long