Skip to content
Static middleware
Branch: master
Clone or download
Latest commit c1cdf9c May 11, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example fix: replace gopkg with github. (#1) Mar 11, 2017
.gitignore remove vendor files. (#5) Mar 15, 2017
.travis.yml Update .travis.yml Mar 1, 2019
LICENSE Initial commit Dec 13, 2016
README.md feat: add embedmd (#3) Mar 11, 2017
go.mod Fix go module issue. May 9, 2019
go.sum Fix go module issue. May 9, 2019
static.go fix: import order. Aug 27, 2018
static_test.go fix: import order. Aug 27, 2018

README.md

static middleware

Build Status codecov Go Report Card GoDoc

Static middleware

Usage

Start using it

Download and install it:

$ go get github.com/gin-contrib/static

Import it in your code:

import "github.com/gin-contrib/static"

Canonical example:

See the example

package main

import (
	"github.com/gin-contrib/static"
	"github.com/gin-gonic/gin"
)

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

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

	r.Use(static.Serve("/", static.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")
}
You can’t perform that action at this time.