handlers

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

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

Go to latest
Published: Jan 14, 2015 License: ISC Imports: 6 Imported by: 0

README

Handlers GoDoc Build Status Coverage Status

A collection of handlers for use with Go's net/http package.

See godoc.org/github.com/maxnordlund/handlers for documentation.

Documentation

Overview

Package handlers provides handlers for use with Go's net/http package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTarFileSystem

func NewTarFileSystem(tr *tar.Reader) (http.FileSystem, error)

NewTarFileSystem returns a http.FileSystem backed by the provided tar file.

Example
package main

import (
	"archive/tar"
	"compress/gzip"
	"github.com/maxnordlund/handlers"
	"log"
	"net/http"
	"os"
)

func main() {
	// Open some tar with the files to be served.
	gz, err := os.Open("website.tar.gz")
	if err != nil {
		log.Fatalln(err)
	}

	// Make sure to decompress it, if needed.
	archive, err := gzip.NewReader(gz)
	if err != nil {
		log.Fatalln(err)
	}

	// Pass the tar to the handler.
	fs, err := handlers.NewTarFileSystem(tar.NewReader(archive))
	if err != nil {
		log.Fatalln(err)
	}

	// Finally pass the handler to http.FileSystem to start serving the files.
	log.Fatalln(http.ListenAndServe(":8080", http.FileServer(fs)))
}
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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