staticbin

package module
v0.0.0-...-b9631fb Latest Latest
Warning

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

Go to latest
Published: May 17, 2014 License: MIT Imports: 6 Imported by: 17

README

StaticBin wercker status GoDoc

Martini middleware/handler for serving static files from binary data

Usage

package main

import (
	"github.com/go-martini/martini"
	"github.com/martini-contrib/staticbin"
)

func main() {
	m := martini.Classic()

	// Serves the "static" directory's files from binary data.
	// You have to pass the "Asset" function generated by
	// go-bindata (https://github.com/jteeuwen/go-bindata).
	m.Use(staticbin.Static("static", Asset))

	m.Get("/", func() string {
		return "Hello world!"
	})

	m.Run()
}

Get a classic Martini which serves the "public" directory's files from binary data by default

A classic Martini generated by martini.Classic serves the "public" directory's files by default. You can get one which serves the "public" directory's files from binary data by default by using staticbin.Classic.

package main

import "github.com/martini-contrib/staticbin"

func main() {
	// staticbin.Classic(Asset) instance automatically serves the "public" directory's files
	// from binary data by default.
	m := staticbin.Classic(Asset)

	// You can serve from more directories by adding more staticbin.Static handlers.
	//   m.Use(staticbin.Static("static", Asset))

	m.Get("/", func() string {
		return "Hello world!"
	})

	m.Run()
}

Sample package using StaticBin

Doc

Documentation

Overview

Package staticbin provides a Martini middleware/handler for serving static files from binary data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Classic

func Classic(asset func(string) ([]byte, error)) *martini.ClassicMartini

Classic creates a classic Martini with a default Static.

func ClassicWithoutStatic

func ClassicWithoutStatic() *martini.ClassicMartini

ClassicWithoutStatic creates a classic Martini without a default Static.

func Static

func Static(dir string, asset func(string) ([]byte, error), options ...Options) martini.Handler

Static returns a middleware handler that serves static files in the given directory.

Types

type Options

type Options struct {
	// SkipLogging will disable [Static] log messages when a static file is served.
	SkipLogging bool
	// IndexFile defines which file to serve as index if it exists.
	IndexFile string
}

Options represents configuration options for the staticbin.Static middleware.

Jump to

Keyboard shortcuts

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