dip/src/static/main.go
Paul bb2a195007
All checks were successful
continuous-integration/drone/push Build is passing
added favicon
2024-05-14 11:46:29 +02:00

36 lines
867 B
Go

package static
import (
"embed"
"log"
"net/http"
"strings"
"github.com/labstack/echo/v4"
)
// GetStatic returns static file content
func GetStatic(staticfiles *embed.FS, c echo.Context) (err error) {
name := c.Param("*")
content, err := staticfiles.ReadFile(name)
if err != nil {
log.Println(err)
}
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")
} else if strings.HasSuffix(name, ".ico") {
c.Response().Header().Set(echo.HeaderContentType, "image/x-icon")
}
c.Response().Header().Add(echo.HeaderCacheControl, "max-age=172800")
return c.String(http.StatusOK, string(content))
}
// Static defines static file
type Static struct {
Name string
Content string
}