static

package
v1.7.10 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 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("./testdata/favicon.ico"))
	app.Use(static.New(static.Options{
		Root:        "./testdata",
		Prefix:      "/",
		StripPrefix: false,
	}))
	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`.
	Files       map[string][]byte // Optional, a map of File objects to serve.
}

Options is static middleware options

Jump to

Keyboard shortcuts

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