Skip to content

glebtv/static_gzipped

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

static middleware

Build Status codecov Go Report Card GoDoc

Static-Gzipped middleware for gin

Automatically serves pre-gzipped files with gzipped.FileServer

Like gzip_static from nginx, but for gin / go.

WARNING

This is incompatible with gzip middleware because it will double-compress already gzipped files. Can be used with groups: gin-gonic/gin#1125

Usage

Start using it

Download and install it:

$ go get github.com/glebtv/static_gzipped

Import it in your code:

import "github.com/glebtv/static_gzipped"

Canonical example:

See the example

package main

import (
  "github.com/glebtv/static_gzipped"
	"github.com/gin-gonic/gin"
)

func main() {
	r := gin.Default()

	// if Allow DirectoryIndex
	//r.Use(static_gzipped.Serve("/", static_gzipped.LocalFile("/tmp", true)))
	// set prefix
	//r.Use(static_gzipped.Serve("/static", static_gzipped.LocalFile("/tmp", true)))

	r.Use(static_gzipped.Serve("/", static_gzipped.LocalFile("/tmp", false)))
	r.GET("/ping", func(c *gin.Context) {
		c.String(200, "test")
	})
	// Listen and Server in 0.0.0.0:8080
	r.Run(":8080")
}

About

Static middleware

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 97.9%
  • HTML 2.1%