token-validator: use go-bindata to embedded static assets
This commit is contained in:
parent
37acc213b7
commit
867b4ef194
7 changed files with 75 additions and 14 deletions
|
@ -1,29 +1,61 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
//go:generate go-bindata -ignore "\\.go|\\.less" -pkg "main" -o "bindata.go" htdocs/...
|
||||
//go:generate go fmt bindata.go
|
||||
|
||||
func init() {
|
||||
router.GET("/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, "index.html"))
|
||||
Router().GET("/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
if data, err := Asset("htdocs/index.html"); err != nil {
|
||||
fmt.Fprintf(w, "{\"errmsg\":%q}", err)
|
||||
} else {
|
||||
w.Write(data)
|
||||
}
|
||||
})
|
||||
router.GET("/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
|
||||
Router().GET("/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Content-Type", "text/css")
|
||||
if data, err := Asset(path.Join("htdocs", r.URL.Path)); err != nil {
|
||||
http.NotFound(w, r)
|
||||
} else {
|
||||
w.Write(data)
|
||||
}
|
||||
})
|
||||
router.GET("/fonts/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
Router().GET("/fonts/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
if data, err := Asset(path.Join("htdocs", r.URL.Path)); err != nil {
|
||||
http.NotFound(w, r)
|
||||
} else {
|
||||
w.Write(data)
|
||||
}
|
||||
})
|
||||
router.GET("/img/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
Router().GET("/img/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
if data, err := Asset(path.Join("htdocs", r.URL.Path)); err != nil {
|
||||
http.NotFound(w, r)
|
||||
} else {
|
||||
w.Write(data)
|
||||
}
|
||||
})
|
||||
router.GET("/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
Router().GET("/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Content-Type", "text/javascript")
|
||||
if data, err := Asset(path.Join("htdocs", r.URL.Path)); err != nil {
|
||||
http.NotFound(w, r)
|
||||
} else {
|
||||
w.Write(data)
|
||||
}
|
||||
})
|
||||
router.GET("/views/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
Router().GET("/views/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
if data, err := Asset(path.Join("htdocs", r.URL.Path)); err != nil {
|
||||
http.NotFound(w, r)
|
||||
} else {
|
||||
w.Write(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Reference in a new issue