static

package
v1.8.10 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2017 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts Options) gear.Middleware

New creates a static middleware to serves static content from the provided root directory.

package main

import (
	"github.com/teambition/gear"
	"github.com/teambition/gear/middleware/favicon"
	"github.com/teambition/gear/middleware/static"
)

func main() {
	app := gear.New()
	app.Use(favicon.New("./assets/favicon.ico"))
	app.Use(static.New(static.Options{
		Root:        "./assets",
		Prefix:      "/assets",
		StripPrefix: false,
		Includes:    []string{"/robots.txt"},
	}))
	app.Use(func(ctx *gear.Context) error {
		return ctx.HTML(200, "<h1>Hello, Gear!</h1>")
	})
	app.Error(app.Listen(":3000"))
}

Types

type Options

type Options struct {
	Root        string            // The directory you wish to serve
	Prefix      string            // The url prefix you wish to serve as static request, default to `'/'`.
	StripPrefix bool              // Strip the prefix from URL path, default to `false`.
	Includes    []string          // Optional, a slice of file path to serve, it will ignore Prefix and StripPrefix options.
	Files       map[string][]byte // Optional, a map of File objects to serve.
	OnlyFiles   bool              // Optional, if Options.Files provided and Options.OnlyFiles is true, it will not seek files in other way.
}

Options is static middleware options

Jump to

Keyboard shortcuts

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