assets stored in binary

This commit is contained in:
Daniel 2020-01-26 12:58:59 +01:00
parent 2d8d26323e
commit 6953bd744b
8 changed files with 240 additions and 4 deletions

View file

@ -1,10 +1,22 @@
build: get
swag init
go build
full: build_web build_swagger build
get:
go get ./...
build_swagger:
swag init
build_web: get_web
cd web && npm run build
go run api/assets.go
get_web:
cd web && npm install
# Docker stuff
container:
docker build -t gempir/justlog .

22
api/assets.go Normal file
View file

@ -0,0 +1,22 @@
// +build ignore
package main
import (
"log"
"net/http"
"github.com/shurcooL/vfsgen"
)
var assets http.FileSystem = http.Dir("web/public")
func main() {
err := vfsgen.Generate(assets, vfsgen.Options{
Filename: "api/assets_vfsgen.go",
PackageName: "api",
})
if err != nil {
log.Fatalln(err)
}
}

192
api/assets_vfsgen.go Normal file

File diff suppressed because one or more lines are too long

View file

@ -66,8 +66,9 @@ func (s *Server) Init() {
}))
e.Use(middleware.CORSWithConfig(DefaultCORSConfig))
e.Static("/", "web/public/index.html")
e.Static("/bundle.js", "web/public/bundle.js")
assetHandler := http.FileServer(assets)
e.GET("/", echo.WrapHandler(assetHandler))
e.GET("/bundle.js", echo.WrapHandler(assetHandler))
e.GET("/docs", func(c echo.Context) error {
return c.Redirect(http.StatusMovedPermanently, "/index.html")

2
go.mod
View file

@ -7,6 +7,8 @@ require (
github.com/gempir/go-twitch-irc/v2 v2.2.0
github.com/json-iterator/go v1.1.7
github.com/labstack/echo/v4 v4.0.0
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
github.com/sirupsen/logrus v1.4.2
github.com/swaggo/echo-swagger v0.0.0-20190329130007-1219b460a043
github.com/swaggo/swag v1.6.2

4
go.sum
View file

@ -56,6 +56,10 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 h1:bUGsEnyNbVPw06Bs80sCeARAlK8lhwqGyi6UT8ymuGk=
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

3
package-lock.json generated Normal file
View file

@ -0,0 +1,3 @@
{
"lockfileVersion": 1
}

2
web/package-lock.json generated
View file

@ -1,5 +1,5 @@
{
"name": "logsearch",
"name": "justlog-web",
"requires": true,
"lockfileVersion": 1,
"dependencies": {