Skip to content

Commit 7d80f0e

Browse files
committed
[feature] Use packr to include UI files into binary
1 parent f4dd83a commit 7d80f0e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cmd/ssl-game-controller/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"github.com/g3force/ssl-game-controller/internal/app/controller"
5+
"github.com/gobuffalo/packr"
56
"net/http"
67
)
78

@@ -10,8 +11,9 @@ func main() {
1011
g := controller.NewGameController()
1112
g.Run()
1213

13-
// serve the static resource of UI (for production use only)
14-
http.Handle("/", http.FileServer(http.Dir(".")))
14+
box := packr.NewBox("../../ui/dist")
15+
http.Handle("/", http.FileServer(box))
16+
1517
// serve the bidirectional web socket
1618
http.HandleFunc("/ws", g.ApiServer.WsHandler)
1719
http.ListenAndServe(":8081", nil)

release.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
# stop on errors
4+
set -e
5+
6+
echo "Build UI for production"
7+
cd ui
8+
npm run build
9+
cd ..
10+
11+
echo "Build backend and include static UI files with packr into binary"
12+
cd cmd/ssl-game-controller
13+
packr install
14+
15+
if [ -z "${GOPATH}" ]; then
16+
GOPATH="~/go"
17+
fi
18+
echo "Self-contained binary can be found here: ${GOPATH}/bin/ssl-game-controller"

0 commit comments

Comments
 (0)