Embed static assets into binary
This commit is contained in:
parent
a044bb759e
commit
5f1d7adaa4
1 changed files with 11 additions and 1 deletions
12
main.go
12
main.go
|
@ -2,8 +2,10 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"embed"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -19,6 +21,9 @@ import (
|
|||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
//go:embed all:static
|
||||
var _assets embed.FS
|
||||
|
||||
// Structures de données
|
||||
type WiFiNetwork struct {
|
||||
SSID string `json:"ssid"`
|
||||
|
@ -132,7 +137,12 @@ func main() {
|
|||
r.HandleFunc("/ws/logs", websocketHandler)
|
||||
|
||||
// Servir les fichiers statiques
|
||||
r.PathPrefix("/").Handler(http.FileServer(http.Dir("./static/")))
|
||||
sub, err := fs.Sub(_assets, "static")
|
||||
if err != nil {
|
||||
log.Fatal("Unable to cd to static/ directory:", err)
|
||||
}
|
||||
Assets := http.FS(sub)
|
||||
r.PathPrefix("/").Handler(http.FileServer(Assets))
|
||||
|
||||
addLog("Système", "Serveur API démarré sur le port 8080")
|
||||
log.Fatal(http.ListenAndServe(":8080", r))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue