Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate from packr to go:embed #581

Merged
merged 2 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Loading
Loading