gzipstatic

package module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2025 License: BSD-3-Clause Imports: 7 Imported by: 0

README

gzipstatic-gin

使用静态 gzip 或 br 压缩文件响应,减少服务器性能占用。

Use static gzip or br compression file response to reduce server performance consumption.


Get

go get github.com/bddjr/gzipstatic-gin

Example

NoRoute
noRoute := func(ctx *gin.Context) {
    f, _ := os.ReadFile("frontend/dist/404.html")
    ctx.Data(404, gin.MIMEHTML, f)
}
Router.NoRoute(noRoute)

gzipstatic.NoRoute = noRoute
Static
// router.Static("/", "frontend/dist")
gzipstatic.Static(router, "/", "frontend/dist")
StaticFile
// router.StaticFile("/", "frontend/dist/index.html")
gzipstatic.StaticFile(router, "/", "frontend/dist/index.html")
File
// ctx.File("frontend/dist/index.html")
gzipstatic.File(ctx, "frontend/dist/index.html")
StaticFS
// router.StaticFS("/", "/", fs)
gzipstatic.StaticFS(router, "/", "/", fs)
StaticFileFS
// router.StaticFileFS("/", "index.html", fs)
gzipstatic.StaticFileFS(router, "/", "index.html", fs)
FileFromFS
// ctx.FileFromFS("index.html", fs)
gzipstatic.FileFromFS(ctx, "index.html", fs)
ExtFillter
gzipstatic.ExtFillter = regexp.MustCompile(`\.(html|htm|js|json|css)$`)
EncodeList
// Priority from high to low
gzipstatic.EncodeList = []*gzipstatic.EncodeListItem{
    {
        name: "br",
        ext:  ".br",
    }, {
        name: "gzip",
        ext:  ".gz",
    },
}
EnableDebugHeader
// Encoding-By: gzipstatic-gin
gzipstatic.EnableDebugHeader = true

Source Code

gzipstatic.go


Reference

https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Encoding
https://developer.mozilla.org/docs/Web/HTTP/Headers/Accept-Encoding
https://developer.mozilla.org/docs/Web/HTTP/Headers/Vary
https://github.com/gin-gonic/gin
https://github.com/BCSPanel/BCSPanel/blob/main/src/httprouter/init.go
https://github.com/lpar/gzipped
https://github.com/nanmu42/gzip
https://github.com/vbenjs/vite-plugin-compression


License

BSD-3-clause license

Documentation

Overview

https://github.com/bddjr/gzipstatic-gin

Index

Constants

This section is empty.

Variables

View Source
var EnableDebugHeader = true

Encoding-By: gzipstatic-gin

View Source
var EncodeList = []*EncodeListItem{
	{
		// contains filtered or unexported fields
	}, {
		// contains filtered or unexported fields
	},
}

Priority from high to low

View Source
var ExtFillter = regexp.MustCompile(`\.(html|htm|js|json|css)$`)
View Source
var NoRoute gin.HandlerFunc = nil

Functions

func File

func File(ctx *gin.Context, FilePath string)

func FileFromFS

func FileFromFS(ctx *gin.Context, name string, fs http.FileSystem)

func Static

func Static(group gin.IRoutes, relativePath, root string) gin.IRoutes

func StaticFS

func StaticFS(group gin.IRoutes, relativePath string, fs http.FileSystem) gin.IRoutes

func StaticFile

func StaticFile(group gin.IRoutes, relativePath, filepath string) gin.IRoutes

func StaticFileFS

func StaticFileFS(group gin.IRoutes, relativePath, filepath string, fs http.FileSystem) gin.IRoutes

Types

type EncodeListItem

type EncodeListItem struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL