21 lines
513 B
Go
21 lines
513 B
Go
package static
|
|
|
|
import (
|
|
"github.com/gobuffalo/packr/v2"
|
|
"github.com/labstack/echo/v4"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// Static ...
|
|
func Static(box *packr.Box, c echo.Context) (err error) {
|
|
name := c.Param("*")
|
|
cnt, _ := box.FindString(name)
|
|
if strings.HasSuffix(name, ".js") {
|
|
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScript)
|
|
} else if strings.HasSuffix(name, ".css") {
|
|
c.Response().Header().Set(echo.HeaderContentType, "text/css")
|
|
}
|
|
return c.String(http.StatusOK, cnt)
|
|
}
|