Skip to content

Commit

Permalink
Use go:embed to serve static resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
riannucci committed Oct 26, 2021
1 parent 3bb3368 commit 29d2f9a
Showing 1 changed file with 11 additions and 4 deletions.
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")
}

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

0 comments on commit 29d2f9a

Please sign in to comment.