mirror of
https://github.com/Luzifer/password.git
synced 2024-12-20 04:41:17 +00:00
Switch from bindata to go:embed
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
ac72a04c53
commit
509aed10d8
4 changed files with 10 additions and 20586 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,5 +1,5 @@
|
||||||
cmd/password/.build
|
cmd/password/.build
|
||||||
|
cmd/password/frontend/assets/*
|
||||||
cmd/password/password
|
cmd/password/password
|
||||||
dist
|
dist
|
||||||
frontend/assets/*
|
|
||||||
js/node_modules/*
|
js/node_modules/*
|
||||||
|
|
20580
cmd/password/bindata.go
20580
cmd/password/bindata.go
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"mime"
|
"mime"
|
||||||
|
@ -18,6 +19,9 @@ import (
|
||||||
|
|
||||||
const defaultHTTPListenPort = 3000
|
const defaultHTTPListenPort = 3000
|
||||||
|
|
||||||
|
//go:embed frontend/**
|
||||||
|
var frontend embed.FS
|
||||||
|
|
||||||
func getCmdServe() *cobra.Command {
|
func getCmdServe() *cobra.Command {
|
||||||
cmd := cobra.Command{
|
cmd := cobra.Command{
|
||||||
Use: "serve",
|
Use: "serve",
|
||||||
|
@ -79,7 +83,7 @@ func handleAPIGetPasswordv1(res http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func handleFrontend(res http.ResponseWriter, r *http.Request) {
|
func handleFrontend(res http.ResponseWriter, r *http.Request) {
|
||||||
res.Header().Add("Content-Type", "text/html")
|
res.Header().Add("Content-Type", "text/html")
|
||||||
buf, err := Asset("frontend/index.html")
|
buf, err := frontend.ReadFile("frontend/index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(res, "Unable to load interface", http.StatusInternalServerError)
|
http.Error(res, "Unable to load interface", http.StatusInternalServerError)
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
@ -89,7 +93,7 @@ func handleFrontend(res http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleAssets(res http.ResponseWriter, r *http.Request) {
|
func handleAssets(res http.ResponseWriter, r *http.Request) {
|
||||||
buf, err := Asset(fmt.Sprintf("frontend%s", r.URL.Path))
|
buf, err := frontend.ReadFile(fmt.Sprintf("frontend%s", r.URL.Path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(res, "Unable to load interface", http.StatusInternalServerError)
|
http.Error(res, "Unable to load interface", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
|
@ -5,8 +5,7 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<title>Secure Password</title>
|
<title>Secure Password</title>
|
||||||
|
|
||||||
<!-- Load app script early to prevent blank HTML without styling -->
|
<link rel="stylesheet" href="assets/bundle.css">
|
||||||
<script src="assets/bundle.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||||
|
@ -116,5 +115,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="assets/bundle.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue