Skip to content

Commit

Permalink
cmd/memlat: replace custom static embed with go:embed
Browse files Browse the repository at this point in the history
  • Loading branch information
aclements committed Jul 11, 2022
1 parent fc9d1ba commit 99ebd9f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 36,667 deletions.
23 changes: 8 additions & 15 deletions cmd/memlat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ package main

import (
"bufio"
"embed"
"encoding/json"
"flag"
"fmt"
"io/fs"
"log"
"net/http"
"net/url"
Expand All @@ -89,11 +91,8 @@ import (
"github.com/aclements/go-perf/perffile"
)

//go:generate go run makestatic.go

// staticFiles is the static file tree baked in to the binary. This is
// assigned by an init function if the static files are available.
var staticFiles mapFS
//go:embed static
var staticFiles embed.FS

// TODO: Open a browser automatically. Maybe bind to any address in
// this mode.
Expand All @@ -112,24 +111,18 @@ func main() {
flag.Usage()
os.Exit(1)
}
if *flagDocRoot == "" && staticFiles == nil {
// No baked-in static file system.
*flagDocRoot = "static"
fi, err := os.Stat(*flagDocRoot)
if err != nil || !fi.IsDir() {
fmt.Fprintln(os.Stderr, "static assets not found; please specify -docroot")
os.Exit(1)
}
}

fmt.Fprintln(os.Stderr, "loading profile...")
db := parsePerf(*flagInput)
fmt.Fprintln(os.Stderr, "profile loaded")

mux := http.NewServeMux()
if *flagDocRoot == "" {
mux.Handle("/", http.FileServer(staticFiles))
// Use the embedded static assets.
sub, _ := fs.Sub(staticFiles, "static")
mux.Handle("/", http.FileServer(http.FS(sub)))
} else {
// Use assets from the file system.
mux.Handle("/", http.FileServer(http.Dir(*flagDocRoot)))
}
mux.Handle("/h", &heatMapHandler{db})
Expand Down
82 changes: 0 additions & 82 deletions cmd/memlat/makestatic.go

This file was deleted.

86 changes: 0 additions & 86 deletions cmd/memlat/mapfs.go

This file was deleted.

Loading

0 comments on commit 99ebd9f

Please sign in to comment.