-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Description
Hi, would it a good idea to embed the docs into the build/binary?
This way it would produce a single binary that does not need/depends on the "docs" static files
--- a/main.go
+++ b/main.go
@@ -2,7 +2,9 @@ package main
import (
"crypto/tls"
+ "embed"
"fmt"
+ "io/fs"
"log"
"net"
"net/http"
@@ -13,6 +15,9 @@ import (
"golang.org/x/net/publicsuffix"
)
+//go:embed docs
+var embedDocs embed.FS
+
func main() {
port := os.Getenv("PORT")
if port == "" {
@@ -30,8 +35,9 @@ func main() {
}
func router(middlewares ...Middleware) http.Handler {
+ docsRoot, _ := fs.Sub(embedDocs, "docs")
mux := http.NewServeMux()
- mux.Handle("/", http.FileServer(http.Dir("docs")))
+ mux.Handle("/", http.FileServer(http.FS(docsRoot)))
mux.HandleFunc("GET /{room}/announce", announce)
mux.HandleFunc("GET /{room}/scrape", scrape)
return chainMiddleware(mux, middlewares...)Just a suggestion that I think makes it easy to run and to package the project.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels