static_gzipped

package module
v0.0.0-...-2301909 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2018 License: MIT Imports: 6 Imported by: 2

README

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: https://github.com/gin-gonic/gin/issues/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")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LocalFile

func LocalFile(root string, indexes bool) *localFileSystem

func Serve

func Serve(urlPrefix string, fs ServeFileSystem) gin.HandlerFunc

Static returns a middleware handler that serves static files in the given directory.

func ServeRoot

func ServeRoot(urlPrefix, root string) gin.HandlerFunc

Types

type ServeFileSystem

type ServeFileSystem interface {
	http.FileSystem
	Exists(prefix string, path string) bool
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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