mirror of
https://github.com/sosedoff/pgweb.git
synced 2024-12-14 19:21:46 +03:00
Merge pull request #510 from MobileTeleSystems/go-1-16-embed
go 1.16 features
This commit is contained in:
commit
4adba368c4
@ -11,14 +11,10 @@ addons:
|
|||||||
postgresql: "9.6"
|
postgresql: "9.6"
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- "1.12"
|
- "1.16"
|
||||||
- "1.13"
|
|
||||||
- "1.14"
|
|
||||||
- "1.15"
|
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- ./script/check_formatting.sh
|
- ./script/check_formatting.sh
|
||||||
- ./script/check_assets.sh
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- make setup
|
- make setup
|
||||||
@ -27,4 +23,4 @@ script:
|
|||||||
- make build
|
- make build
|
||||||
- make test
|
- make test
|
||||||
- make test-all
|
- make test-all
|
||||||
- make docker-release
|
- make docker-release
|
29
Makefile
29
Makefile
@ -2,7 +2,6 @@ TARGETS = darwin/amd64 linux/amd64 linux/386 windows/amd64 windows/386
|
|||||||
GIT_COMMIT = $(shell git rev-parse HEAD)
|
GIT_COMMIT = $(shell git rev-parse HEAD)
|
||||||
BUILD_TIME = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" | tr -d '\n')
|
BUILD_TIME = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" | tr -d '\n')
|
||||||
GO_VERSION = $(shell go version | awk {'print $$3'})
|
GO_VERSION = $(shell go version | awk {'print $$3'})
|
||||||
BINDATA_IGNORE = $(shell git ls-files -io --exclude-standard $< | sed 's/^/-ignore=/;s/[.]/[.]/g')
|
|
||||||
DOCKER_RELEASE_TAG = "sosedoff/pgweb:$(shell git describe --abbrev=0 --tags | sed 's/v//')"
|
DOCKER_RELEASE_TAG = "sosedoff/pgweb:$(shell git describe --abbrev=0 --tags | sed 's/v//')"
|
||||||
DOCKER_LATEST_TAG = "sosedoff/pgweb:latest"
|
DOCKER_LATEST_TAG = "sosedoff/pgweb:latest"
|
||||||
|
|
||||||
@ -18,35 +17,29 @@ usage:
|
|||||||
@echo "make test : Execute test suite"
|
@echo "make test : Execute test suite"
|
||||||
@echo "make test-all : Execute test suite on multiple PG versions"
|
@echo "make test-all : Execute test suite on multiple PG versions"
|
||||||
@echo "make clean : Remove all build files and reset assets"
|
@echo "make clean : Remove all build files and reset assets"
|
||||||
@echo "make assets : Generate production assets file"
|
|
||||||
@echo "make dev-assets : Generate development assets file"
|
|
||||||
@echo "make docker : Build docker image"
|
@echo "make docker : Build docker image"
|
||||||
@echo "make docker-release : Build and tag docker image"
|
@echo "make docker-release : Build and tag docker image"
|
||||||
@echo "make docker-push : Push docker images to registry"
|
@echo "make docker-push : Push docker images to registry"
|
||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
test:
|
test:
|
||||||
GO111MODULE=on go test -race -cover ./pkg/...
|
go test -race -cover ./pkg/...
|
||||||
|
|
||||||
test-all:
|
test-all:
|
||||||
@./script/test_all.sh
|
@./script/test_all.sh
|
||||||
@./script/test_cockroach.sh
|
@./script/test_cockroach.sh
|
||||||
|
|
||||||
assets: static/
|
|
||||||
go-bindata -o pkg/data/bindata.go -pkg data $(BINDATA_OPTS) $(BINDATA_IGNORE) -ignore=[.]gitignore -ignore=[.]gitkeep $<...
|
|
||||||
|
|
||||||
dev-assets:
|
|
||||||
@$(MAKE) --no-print-directory assets BINDATA_OPTS="-debug"
|
|
||||||
|
|
||||||
dev: dev-assets
|
dev:
|
||||||
GO111MODULE=on go build
|
go build
|
||||||
@echo "You can now execute ./pgweb"
|
@echo "You can now execute ./pgweb"
|
||||||
|
|
||||||
build: assets
|
build:
|
||||||
GO111MODULE=on go build
|
go build
|
||||||
@echo "You can now execute ./pgweb"
|
@echo "You can now execute ./pgweb"
|
||||||
|
|
||||||
release: clean assets
|
release:
|
||||||
@echo "Building binaries..."
|
@echo "Building binaries..."
|
||||||
@gox \
|
@gox \
|
||||||
-osarch "$(TARGETS)" \
|
-osarch "$(TARGETS)" \
|
||||||
@ -54,12 +47,12 @@ release: clean assets
|
|||||||
-output "./bin/pgweb_{{.OS}}_{{.Arch}}"
|
-output "./bin/pgweb_{{.OS}}_{{.Arch}}"
|
||||||
|
|
||||||
@echo "Building ARM binaries..."
|
@echo "Building ARM binaries..."
|
||||||
GO111MODULE=on GOOS=linux GOARCH=arm GOARM=5 go build \
|
GOOS=linux GOARCH=arm GOARM=5 go build \
|
||||||
-ldflags "-s -w -X github.com/sosedoff/pgweb/pkg/command.GitCommit=$(GIT_COMMIT) -X github.com/sosedoff/pgweb/pkg/command.BuildTime=$(BUILD_TIME) -X github.com/sosedoff/pgweb/pkg/command.GoVersion=$(GO_VERSION)" \
|
-ldflags "-s -w -X github.com/sosedoff/pgweb/pkg/command.GitCommit=$(GIT_COMMIT) -X github.com/sosedoff/pgweb/pkg/command.BuildTime=$(BUILD_TIME) -X github.com/sosedoff/pgweb/pkg/command.GoVersion=$(GO_VERSION)" \
|
||||||
-o "./bin/pgweb_linux_arm_v5"
|
-o "./bin/pgweb_linux_arm_v5"
|
||||||
|
|
||||||
@echo "Building ARM64 binaries..."
|
@echo "Building ARM64 binaries..."
|
||||||
GO111MODULE=on GOOS=linux GOARCH=arm64 GOARM=7 go build \
|
GOOS=linux GOARCH=arm64 GOARM=7 go build \
|
||||||
-ldflags "-s -w -X github.com/sosedoff/pgweb/pkg/command.GitCommit=$(GIT_COMMIT) -X github.com/sosedoff/pgweb/pkg/command.BuildTime=$(BUILD_TIME) -X github.com/sosedoff/pgweb/pkg/command.GoVersion=$(GO_VERSION)" \
|
-ldflags "-s -w -X github.com/sosedoff/pgweb/pkg/command.GitCommit=$(GIT_COMMIT) -X github.com/sosedoff/pgweb/pkg/command.BuildTime=$(BUILD_TIME) -X github.com/sosedoff/pgweb/pkg/command.GoVersion=$(GO_VERSION)" \
|
||||||
-o "./bin/pgweb_linux_arm64_v7"
|
-o "./bin/pgweb_linux_arm64_v7"
|
||||||
|
|
||||||
@ -70,13 +63,11 @@ bootstrap:
|
|||||||
gox -build-toolchain
|
gox -build-toolchain
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
go get -u github.com/mitchellh/gox
|
go install github.com/mitchellh/gox@v1.0.1
|
||||||
go get -u github.com/go-bindata/go-bindata/...
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -f ./pgweb
|
@rm -f ./pgweb
|
||||||
@rm -rf ./bin/*
|
@rm -rf ./bin/*
|
||||||
@rm -f bindata.go
|
|
||||||
|
|
||||||
docker:
|
docker:
|
||||||
docker build --no-cache -t pgweb .
|
docker build --no-cache -t pgweb .
|
||||||
@ -88,4 +79,4 @@ docker-release:
|
|||||||
|
|
||||||
docker-push:
|
docker-push:
|
||||||
docker push $(DOCKER_RELEASE_TAG)
|
docker push $(DOCKER_RELEASE_TAG)
|
||||||
docker push $(DOCKER_LATEST_TAG)
|
docker push $(DOCKER_LATEST_TAG)
|
@ -2,13 +2,19 @@ clone_folder: c:\gopath\src\github.com\sosedoff\pgweb
|
|||||||
|
|
||||||
environment:
|
environment:
|
||||||
GOPATH: c:\gopath
|
GOPATH: c:\gopath
|
||||||
|
GOROOT: c:\goroot116\go
|
||||||
|
GOTOOLDIR: c:\goroot116\go\pkg\tool\windows_amd64
|
||||||
CGO_ENABLED: 0
|
CGO_ENABLED: 0
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- postgresql
|
- postgresql
|
||||||
|
|
||||||
install:
|
install:
|
||||||
|
- ps: mkdir c:\goroot116
|
||||||
|
- ps: iwr -outf c:\goroot116\go1.16.windows-amd64.zip https://golang.org/dl/go1.16.windows-amd64.zip
|
||||||
|
- ps: Expand-Archive c:\goroot116\go1.16.windows-amd64.zip -DestinationPath c:\goroot116
|
||||||
- set PATH=%GOPATH%\bin;%PATH%
|
- set PATH=%GOPATH%\bin;%PATH%
|
||||||
|
- set PATH=%GOROOT%\bin;%PATH%
|
||||||
- echo %PATH%
|
- echo %PATH%
|
||||||
- echo %GOPATH%
|
- echo %GOPATH%
|
||||||
- cd %APPVEYOR_BUILD_FOLDER%
|
- cd %APPVEYOR_BUILD_FOLDER%
|
||||||
|
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
|||||||
module github.com/sosedoff/pgweb
|
module github.com/sosedoff/pgweb
|
||||||
|
|
||||||
go 1.12
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v0.3.1
|
github.com/BurntSushi/toml v0.3.1
|
||||||
|
@ -3,6 +3,8 @@ package api
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/sosedoff/pgweb/static"
|
||||||
|
"net/http"
|
||||||
neturl "net/url"
|
neturl "net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
@ -56,13 +58,12 @@ func setClient(c *gin.Context, newClient *client.Client) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetHome renderes the home page
|
// GetHome renderes the home page
|
||||||
func GetHome(c *gin.Context) {
|
func GetHome() http.Handler {
|
||||||
serveStaticAsset("/index.html", c)
|
return http.FileServer(http.FS(static.Static))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAsset renders the requested static asset
|
func GetAssets() http.Handler {
|
||||||
func GetAsset(c *gin.Context) {
|
return http.StripPrefix("/static/", http.FileServer(http.FS(static.Static)))
|
||||||
serveStaticAsset(c.Params.ByName("path"), c)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSessions renders the number of active sessions
|
// GetSessions renders the number of active sessions
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
"github.com/sosedoff/pgweb/pkg/data"
|
|
||||||
"github.com/sosedoff/pgweb/pkg/shared"
|
"github.com/sosedoff/pgweb/pkg/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -145,16 +144,6 @@ func assetContentType(name string) string {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveStaticAsset(path string, c *gin.Context) {
|
|
||||||
data, err := data.Asset("static" + path)
|
|
||||||
if err != nil {
|
|
||||||
c.String(400, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Data(200, assetContentType(path), data)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send a query result to client
|
// Send a query result to client
|
||||||
func serveResult(c *gin.Context, result interface{}, err interface{}) {
|
func serveResult(c *gin.Context, result interface{}, err interface{}) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -20,8 +20,8 @@ func SetupMiddlewares(group *gin.RouterGroup) {
|
|||||||
func SetupRoutes(router *gin.Engine) {
|
func SetupRoutes(router *gin.Engine) {
|
||||||
root := router.Group(command.Opts.Prefix)
|
root := router.Group(command.Opts.Prefix)
|
||||||
|
|
||||||
root.GET("/", GetHome)
|
root.GET("/", gin.WrapH(GetHome()))
|
||||||
root.GET("/static/*path", GetAsset)
|
root.GET("/static/*path", gin.WrapH(GetAssets()))
|
||||||
root.GET("/connect/:resource", ConnectWithBackend)
|
root.GET("/connect/:resource", ConnectWithBackend)
|
||||||
|
|
||||||
api := root.Group("/api")
|
api := root.Group("/api")
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,10 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
if grep -q 'go/src/github.com/sosedoff/pgweb' ./pkg/data/bindata.go
|
|
||||||
then
|
|
||||||
echo "=========================================================="
|
|
||||||
echo "ERROR: Bindata contains development references to assets!"
|
|
||||||
echo "Fix with 'make assets' and commit the change."
|
|
||||||
echo "=========================================================="
|
|
||||||
exit 1
|
|
||||||
fi
|
|
@ -1,8 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Run the fmt on bindata so it does not trigger failure
|
|
||||||
go fmt ./pkg/data/bindata.go > /dev/null
|
|
||||||
|
|
||||||
# Get list of offending files
|
# Get list of offending files
|
||||||
files="$(go fmt ./pkg/...)"
|
files="$(go fmt ./pkg/...)"
|
||||||
|
|
||||||
|
7
static/data.go
Normal file
7
static/data.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package static
|
||||||
|
|
||||||
|
import "embed"
|
||||||
|
|
||||||
|
//go:embed img/* js/* css/* fonts/*
|
||||||
|
//go:embed index.html
|
||||||
|
var Static embed.FS
|
Loading…
Reference in New Issue
Block a user