Skip to content

Commit

Permalink
Migrate from packr to go:embed (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
eternal-flame-AD committed Jul 15, 2023
1 parent 5cd2d54 commit aedc3e2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 200 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Expand Up @@ -24,16 +24,15 @@ jobs:
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/yarn.lock') }}
restore-keys: ${{ runner.os }}-node_modules-
- uses: actions/checkout@v2
- run: (cd ui && yarn)
- run: make build-js
- uses: golangci/golangci-lint-action@v3
with:
version: v1.45
args: --timeout=5m
skip-cache: true
- run: go mod download
- run: make download-tools
- run: (cd ui && yarn)
- run: make build-js
- run: make embed-static
- run: make test
- run: make check-ci
- uses: codecov/codecov-action@v1
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Expand Up @@ -40,9 +40,6 @@ check-js:
download-tools:
go install github.com/go-swagger/go-swagger/cmd/swagger@v0.26.1

embed-static:
go run hack/packr/packr.go

update-swagger:
swagger generate spec --scan-models -o docs/spec.json
sed -i 's/"uint64"/"int64"/g' docs/spec.json
Expand Down
13 changes: 5 additions & 8 deletions docs/swagger.go
@@ -1,28 +1,25 @@
package docs

import (
_ "embed"
"strings"

"github.com/gin-gonic/gin"
"github.com/gobuffalo/packr/v2"
"github.com/gotify/location"
)

var box = packr.New("docs", "./")
//go:embed spec.json
var spec string

// Serve serves the documentation.
func Serve(ctx *gin.Context) {
base := location.Get(ctx).Host
if basePathFromQuery := ctx.Query("base"); basePathFromQuery != "" {
base = basePathFromQuery
}
ctx.Writer.WriteString(get(base))
ctx.Writer.WriteString(getSwaggerJSON(base))
}

func get(base string) string {
spec, err := box.FindString("spec.json")
if err != nil {
panic(err)
}
func getSwaggerJSON(base string) string {
return strings.Replace(spec, "localhost", base, 1)
}
13 changes: 0 additions & 13 deletions go.mod
Expand Up @@ -6,7 +6,6 @@ require (
github.com/gin-contrib/gzip v0.0.6
github.com/gin-gonic/gin v1.8.1
github.com/go-playground/validator/v10 v10.11.0
github.com/gobuffalo/packr/v2 v2.7.1
github.com/gorilla/websocket v1.5.0
github.com/gotify/configor v1.0.2
github.com/gotify/location v0.0.0-20170722210143-03bc4ad20437
Expand All @@ -27,13 +26,8 @@ require (
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-sql-driver/mysql v1.5.0 // indirect
github.com/go-yaml/yaml v2.1.0+incompatible // indirect
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/logger v1.0.3 // indirect
github.com/gobuffalo/packd v1.0.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/joho/godotenv v1.3.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lib/pq v1.10.0 // indirect
Expand All @@ -44,17 +38,10 @@ require (
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/spf13/cobra v0.0.6 // indirect
github.com/spf13/pflag v1.0.3 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069 // indirect
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.0.0-20200308013534-11ec41452d41 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down

0 comments on commit aedc3e2

Please sign in to comment.