Skip to content

Commit

Permalink
Merge pull request #644 from smartystreets/embed_static
Browse files Browse the repository at this point in the history
Use go:embed to serve static resources.

This will help allow `goconvey` to be distributed as a standalone binary.
  • Loading branch information
riannucci authored Oct 26, 2021
2 parents 8a06cad + 29d2f9a commit 2967ec0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions goconvey.go
Original file line number Diff line number Diff line change
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 2967ec0

Please sign in to comment.