2015-02-09 23:01:28 -08:00
|
|
|
package web
|
|
|
|
|
2017-01-26 19:15:47 -08:00
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
assetfs "github.com/elazarl/go-bindata-assetfs"
|
|
|
|
)
|
|
|
|
|
2015-02-09 23:01:28 -08:00
|
|
|
//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=web static/...
|
2017-01-26 19:15:47 -08:00
|
|
|
|
|
|
|
func NewServer(sm *http.ServeMux, static string) {
|
|
|
|
var fs http.FileSystem
|
|
|
|
if p, d := filepath.Split(static); d == "static" {
|
|
|
|
static = p
|
|
|
|
}
|
|
|
|
fs = http.Dir(static)
|
|
|
|
if static == "" {
|
|
|
|
fs = &assetfs.AssetFS{
|
|
|
|
Asset: Asset,
|
|
|
|
AssetDir: AssetDir,
|
|
|
|
AssetInfo: AssetInfo,
|
|
|
|
Prefix: "static",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sm.Handle(
|
|
|
|
"/",
|
|
|
|
http.FileServer(fs),
|
|
|
|
)
|
|
|
|
}
|