token-validator: use go-bindata to embedded static assets
This commit is contained in:
parent
37acc213b7
commit
867b4ef194
6
Makefile
6
Makefile
@ -1,4 +1,4 @@
|
||||
all: login-app/login-app
|
||||
all: login-app/login-app token-validator/token-validator
|
||||
|
||||
fonts: fonts/Inconsolata-16b.psf fonts/Inconsolata-16r.psf fonts/Inconsolata-32b.psf fonts/Inconsolata-32r.psf
|
||||
fonts/Inconsolata-16b.psf:
|
||||
@ -10,6 +10,10 @@ fonts/Inconsolata-32b.psf:
|
||||
fonts/Inconsolata-32r.psf:
|
||||
wget https://github.com/xeechou/Inconsolata-psf/raw/master/Inconsolata-32r.psf
|
||||
|
||||
token-validator/token-validator: token-validator/*.go
|
||||
go generate ./token-validator
|
||||
GOOS=linux GOARM=5 GOARCH=arm go build -tags netgo -ldflags '-w -extldflags "-static"' -o $@ ./token-validator
|
||||
|
||||
login-app/login-app: login-app/*.go
|
||||
GOOS=linux GOARCH=amd64 go build -tags netgo -ldflags '-w -extldflags "-static -lncurses"' -o $@ ./login-app
|
||||
|
||||
|
1
token-validator/.gitignore
vendored
1
token-validator/.gitignore
vendored
@ -1 +1,2 @@
|
||||
token-validator
|
||||
bindata.go
|
||||
|
7
token-validator/htdocs/css/bootstrap.min.css
vendored
Normal file
7
token-validator/htdocs/css/bootstrap.min.css
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>AdLin - Tableau d'avancement</title>
|
||||
<link href="css/bootstrap.min.css" type="text/css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="bg-light text-dark">
|
||||
<script src="js/common.js"></script>
|
||||
</body>
|
||||
</html>
|
7
token-validator/htdocs/js/bootstrap.min.js
vendored
Normal file
7
token-validator/htdocs/js/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -57,7 +57,6 @@ func main() {
|
||||
var bind = flag.String("bind", ":8081", "Bind port/socket")
|
||||
var dsn = flag.String("dsn", DSNGenerator(), "DSN to connect to the MySQL server")
|
||||
var baseURL = flag.String("baseurl", "/", "URL prepended to each URL")
|
||||
flag.StringVar(&StaticDir, "static", "./htdocs/", "Directory containing static files")
|
||||
flag.StringVar(&sharedSecret, "sharedsecret", "adelina", "secret used to communicate with remote validator")
|
||||
flag.StringVar(&AuthorizedKeyLocation, "authorizedkeyslocation", Authorizedkeyslocation, "File for allowing user to SSH to the machine")
|
||||
flag.Parse()
|
||||
|
@ -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 New Issue
Block a user