1
0
Fork 0
mirror of https://github.com/Luzifer/password.git synced 2024-11-08 09:20:06 +00:00

Switch from bindata to go:embed

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-06-27 21:39:50 +02:00
parent ac72a04c53
commit 509aed10d8
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D
4 changed files with 10 additions and 20586 deletions

2
.gitignore vendored
View file

@ -1,5 +1,5 @@
cmd/password/.build
cmd/password/frontend/assets/*
cmd/password/password
dist
frontend/assets/*
js/node_modules/*

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
package main
import (
"embed"
"fmt"
"log"
"mime"
@ -18,6 +19,9 @@ import (
const defaultHTTPListenPort = 3000
//go:embed frontend/**
var frontend embed.FS
func getCmdServe() *cobra.Command {
cmd := cobra.Command{
Use: "serve",
@ -79,7 +83,7 @@ func handleAPIGetPasswordv1(res http.ResponseWriter, r *http.Request) {
func handleFrontend(res http.ResponseWriter, r *http.Request) {
res.Header().Add("Content-Type", "text/html")
buf, err := Asset("frontend/index.html")
buf, err := frontend.ReadFile("frontend/index.html")
if err != nil {
http.Error(res, "Unable to load interface", http.StatusInternalServerError)
log.Println(err)
@ -89,7 +93,7 @@ func handleFrontend(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 {
http.Error(res, "Unable to load interface", http.StatusInternalServerError)
return

View file

@ -5,8 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Secure Password</title>
<!-- Load app script early to prevent blank HTML without styling -->
<script src="assets/bundle.js"></script>
<link rel="stylesheet" href="assets/bundle.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
@ -38,7 +37,7 @@
<div class="jumbotron">
<p class="lead center">
I will generate a new secure password every 30 seconds. Just click the password to keep the current one.
I will generate a new secure password every 30 seconds. Just click the password to keep the current one.
</p>
</div>
@ -116,5 +115,6 @@
</div>
</div>
<script src="assets/bundle.js"></script>
</body>
</html>