Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use go:embed to serve static resources. #644

Merged
merged 1 commit into from Oct 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions goconvey.go
Expand Up @@ -5,8 +5,10 @@
package main

import (
"embed"
"flag"
"fmt"
"io/fs"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -54,8 +56,7 @@ func flags() {
func folders() {
_, file, _, _ := runtime.Caller(0)
here := filepath.Dir(file)
static = filepath.Join(here, "/web/client")
reports = filepath.Join(static, "reports")
reports = filepath.Join(filepath.Join(here, "/web/client"), "reports")
riannucci marked this conversation as resolved.
Show resolved Hide resolved
}

func main() {
Expand Down Expand Up @@ -186,8 +187,15 @@ func serveHTTP(server contract.Server, listener net.Listener) {
activateServer(listener)
}

//go:embed web/client
var static embed.FS

func serveStaticResources() {
http.Handle("/", http.FileServer(http.Dir(static)))
webclient, err := fs.Sub(static, "web/client")
if err != nil {
log.Fatal(err)
}
http.Handle("/", http.FileServer(http.FS(webclient)))
}

func serveAjaxMethods(server contract.Server) {
Expand Down Expand Up @@ -303,7 +311,6 @@ var (
excludedDirs string
autoLaunchBrowser bool

static string
reports string

quarterSecond = time.Millisecond * 250
Expand Down