static

package
v1.27.3 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: MIT Imports: 7 Imported by: 13 modules, 13 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.

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