generate working static file
This commit is contained in:
parent
325186b237
commit
96e4a101d8
1
flags.go
1
flags.go
@ -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
gen.go
Normal file
6
gen.go
Normal 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/...
|
20
main.go
20
main.go
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user