gojistatic

package
v0.0.0-...-8430c91 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2015 License: MIT, MIT Imports: 4 Imported by: 1

README

goji-static

Middleware for Goji (https://github.com/zenazn/goji) to serve static content from a directory.

It’s based on the static middleware from Martini (https://github.com/go-martini/martini).

Usage

package main

import (
    “github.com/hypebeast/gojistatic”
    “github.com/zenazn/goji”
)

func main() {
    // Serve static files from “public”
    goji.Use(gojistatic.Static(“public”, gojistatic.StaticOptions{SkipLogging: true}))
    
    // Run Goji
    goji.Serve()
}

Options

goji.Use(“public”, gojistatic.StaticOptions{
	// Prefix is the optional prefix used to serve the static directory content
	Prefix: “static”,
	// Indexfile is the name of the index file that should be served if it exists
	IndexFile: “index.html”,
	// SkipLogging will disable [Static] log messages when a static file is served
	SkipLogging: true,
	// Expires defines which user-defined function to use for producing a HTTP Expires Header
	// https://developers.google.com/speed/docs/insights/LeverageBrowserCaching
	Expires: ExpiresFunc,
})

Default Options

var options []gojistatic.StaticOptions

goji.Use(gojistatic.Static(“public”, options))

// Is the same as the default configuration options:

goji.Use(gojistatic.Static(“public”, gojistatic.StaticOptions{
	Prefix: “”,
	IndexFile: “index.html”,
	SkipLogging: false,
	Expires: nil,
}))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Static

func Static(directory string, options ...StaticOptions) func(http.Handler) http.Handler

Types

type StaticOptions

type StaticOptions struct {
	// Prefix is the optional prefix used to serve the static directory content
	Prefix string
	// Indexfile is teh name of the index file that should be served if it exists
	IndexFile string
	// SkipLogging will disable [Static] log messages when a static file is served
	SkipLogging bool
	// Expires defines which user-defined function to use for producing a HTTP Expires Header
	// https://developers.google.com/speed/docs/insights/LeverageBrowserCaching
	Expires func() string
}

StaticOptions is a struct for specifiying configuration options for the goji-static middleware.

Jump to

Keyboard shortcuts

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