go 1.16 features
- use go embed instead of go-binary and remove all about old assets (go 1.16 feature) - pin gox version (go 1.16 feature) - update ci to go 1.16
This commit is contained in:
@@ -3,6 +3,8 @@ package api
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/sosedoff/pgweb/static"
|
||||
"net/http"
|
||||
neturl "net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -56,13 +58,12 @@ func setClient(c *gin.Context, newClient *client.Client) error {
|
||||
}
|
||||
|
||||
// GetHome renderes the home page
|
||||
func GetHome(c *gin.Context) {
|
||||
serveStaticAsset("/index.html", c)
|
||||
func GetHome() http.Handler {
|
||||
return http.FileServer(http.FS(static.Static))
|
||||
}
|
||||
|
||||
// GetAsset renders the requested static asset
|
||||
func GetAsset(c *gin.Context) {
|
||||
serveStaticAsset(c.Params.ByName("path"), c)
|
||||
func GetAssets() http.Handler {
|
||||
return http.StripPrefix("/static/", http.FileServer(http.FS(static.Static)))
|
||||
}
|
||||
|
||||
// GetSessions renders the number of active sessions
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/sosedoff/pgweb/pkg/data"
|
||||
"github.com/sosedoff/pgweb/pkg/shared"
|
||||
)
|
||||
|
||||
@@ -145,16 +144,6 @@ func assetContentType(name string) string {
|
||||
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
|
||||
func serveResult(c *gin.Context, result interface{}, err interface{}) {
|
||||
if err == nil {
|
||||
|
||||
@@ -20,8 +20,8 @@ func SetupMiddlewares(group *gin.RouterGroup) {
|
||||
func SetupRoutes(router *gin.Engine) {
|
||||
root := router.Group(command.Opts.Prefix)
|
||||
|
||||
root.GET("/", GetHome)
|
||||
root.GET("/static/*path", GetAsset)
|
||||
root.GET("/", gin.WrapH(GetHome()))
|
||||
root.GET("/static/*path", gin.WrapH(GetAssets()))
|
||||
root.GET("/connect/:resource", ConnectWithBackend)
|
||||
|
||||
api := root.Group("/api")
|
||||
|
||||
Reference in New Issue
Block a user