improved loading performances, changed function name in static package
This commit is contained in:
parent
ad68e8ddb5
commit
f7081cd518
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
_ "git.paulbsd.com/paulbsd/dip/packrd"
|
||||
"git.paulbsd.com/paulbsd/dip/src/page"
|
||||
@ -10,13 +11,21 @@ import (
|
||||
"git.paulbsd.com/paulbsd/dip/utils"
|
||||
"github.com/gobuffalo/packr/v2"
|
||||
"github.com/labstack/echo/v4"
|
||||
//"github.com/markbates/pkger"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
)
|
||||
|
||||
func main() {
|
||||
e := echo.New()
|
||||
e.HideBanner = true
|
||||
|
||||
e.Use(middleware.GzipWithConfig(middleware.GzipConfig{
|
||||
Level: 5,
|
||||
}))
|
||||
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
|
||||
AllowOrigins: []string{"*"},
|
||||
AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete},
|
||||
}))
|
||||
|
||||
var host, port string
|
||||
var p page.Page
|
||||
p.Title = "Public IP Address Service"
|
||||
@ -31,8 +40,9 @@ func main() {
|
||||
|
||||
e.GET("/", p.Index)
|
||||
e.GET("/static/*", func(c echo.Context) error {
|
||||
return static.Static(staticbox, c)
|
||||
return static.GetStatic(staticbox, c)
|
||||
})
|
||||
e.OPTIONS("/", echo.MethodNotAllowedHandler)
|
||||
|
||||
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%s", host, port)))
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Static ...
|
||||
func Static(box *packr.Box, c echo.Context) (err error) {
|
||||
// GetStatic returns static file content
|
||||
func GetStatic(box *packr.Box, c echo.Context) (err error) {
|
||||
name := c.Param("*")
|
||||
cnt, _ := box.FindString(name)
|
||||
if strings.HasSuffix(name, ".js") {
|
||||
@ -18,3 +18,9 @@ func Static(box *packr.Box, c echo.Context) (err error) {
|
||||
}
|
||||
return c.String(http.StatusOK, cnt)
|
||||
}
|
||||
|
||||
// Static defines static file
|
||||
type Static struct {
|
||||
Name string
|
||||
Content string
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user