static

package module
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2020 License: MIT Imports: 19 Imported by: 0

README

static

Very simple static website handler for Go.

Example

package main

import (
    "net/http"
    "log"

    "github.com/tidwall/static"
)

func main() {
    handler, err := static.NewHandlerFunc("static_files", nil)
    if err != nil {
        log.Fatal(err)
    }
    http.HandleFunc("/", handler)
    log.Fatal(http.ListenAndServe(":8080", nil))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandlerFunc added in v0.3.0

func NewHandlerFunc(path string, opts *Options) (http.HandlerFunc, error)

NewHandlerFunc returns an http.HandlerFunc that does very simple pages serving from the specified path. The pageData function can be used to return template data.

Types

type Options added in v0.3.0

type Options struct {
	LogOutput io.Writer
	PageData  func(page *Page) error
	FuncMap   map[string]interface{}
	AllowGzip bool
}

Options for the handler

type Page added in v0.2.0

type Page struct {
	LocalPath   string
	ContentType string
	Request     *http.Request
	Error       error
	Response    struct {
		Cookies []*http.Cookie
		Data    interface{}
	}
}

A Page is passed to the pageData function

Jump to

Keyboard shortcuts

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