This commit is contained in:
7
httpserver/embed.go
Normal file
7
httpserver/embed.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package httpserver
|
||||
|
||||
import "github.com/lu4p/binclude"
|
||||
|
||||
//go:generate binclude -gzip
|
||||
|
||||
var embeddedAssets = binclude.Include("web")
|
||||
@@ -1,12 +1,17 @@
|
||||
package httpserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
func (s *server) handleIndex() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "hello world")
|
||||
content, err := s.staticFiles.ReadFile("web/index.html")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Send()
|
||||
}
|
||||
w.Write(content)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/lu4p/binclude"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
@@ -41,6 +42,7 @@ type server struct {
|
||||
cancelFunc context.CancelFunc
|
||||
httpServer *http.Server
|
||||
router *chi.Mux
|
||||
staticFiles *binclude.FileSystem
|
||||
}
|
||||
|
||||
func NewServer(options ...func(s *server)) *server {
|
||||
@@ -61,6 +63,7 @@ func Run(appname, version, buildarch string) int {
|
||||
i.version = version
|
||||
}
|
||||
i.buildarch = buildarch
|
||||
i.staticFiles = BinFS
|
||||
})
|
||||
|
||||
// this does nothing if SENTRY_DSN is unset in env.
|
||||
|
||||
12
httpserver/web/index.html
Normal file
12
httpserver/web/index.html
Normal file
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Title</title>
|
||||
<link rel="stylesheet" href="/s/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello, world!</h1>
|
||||
<script src="/s/js/scripts.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user