static

package module
v0.0.0-...-3fd16bb Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: MIT Imports: 17 Imported by: 0

README

static middleware support pkger

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"
vue html5 history mod
r.Use(static.Serve("/", static.EmbedFile(pkger.Dir("/public"), false, true)))
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")
}

Documentation

Index

Constants

View Source
const INDEX = "index.html"

Variables

This section is empty.

Functions

func EmbedFile

func EmbedFile(root pkger.Dir, indexes bool) *embedFileSystem

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 ServeEmbedFile

func ServeEmbedFile(c *gin.Context, name string)

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