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 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
bindata command
simple command

Jump to

Keyboard shortcuts

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