static

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

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

Go to latest
Published: Jul 3, 2020 License: BSD-3-Clause Imports: 15 Imported by: 0

README

static.v2

GoDoc

Create easily a http Handler for static file.

Installation

go get -u github.com/HuguesGuilleus/static.v2

Example

package main

import (
	"github.com/HuguesGuilleus/static.v2"
	"log"
	"net/http"
)

func main() {
	// To pass in Dev mode.
	// static.Dev = true

	http.HandleFunc("/", static.Html(nil, "front/index.html"))
	http.HandleFunc("/style.css", static.Css(nil, "front/style.css"))
	http.HandleFunc("/app.js", static.Js(nil, "front/app.js"))
	http.HandleFunc("/favicon.png", static.Png(nil, "front/favicon.png"))

	log.Fatal(http.ListenAndServe(":8080", nil))
}

Documentation

Overview

Create easily a http Handler for static file.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Dev disable the minifing and read all SleepDev the files.
	Dev bool = false
	// The duration of sleeping in development mode
	SleepDev time.Duration = 100 * time.Millisecond
)

Functions

func Css

func Css(b []byte, f string) http.HandlerFunc

A binding of File for Css file.

http.HandleFunc("/style.css", static.Css(nil, "front/style/"))

func CssMinify

func CssMinify(in []byte) []byte

func File

func File(b []byte, f string, mime string, min Minifier) http.HandlerFunc

Server a static content with a min Content-Type header.

The content is by default d. If f is non empty, the function read recurrent from f serve it. The reading error are silent.

The served content are minify (expect if Dev is enable) with min. If min is nil, the content are not minify.

func Html

func Html(b []byte, f string) http.HandlerFunc

A binding of File for Html file.

http.HandleFunc("/", static.Html(nil, "front/index.html"))

func HtmlMinify

func HtmlMinify(in []byte) []byte

func Jpeg

func Jpeg(b []byte, f string) http.HandlerFunc

A binding of File for JPEG image.

func Js

func Js(b []byte, f string) http.HandlerFunc

A binding of File for Js file.

http.HandleFunc("/app.js", static.Js(nil, "front/app.js"))

func JsMinify

func JsMinify(in []byte) []byte

func Png

func Png(b []byte, f string) http.HandlerFunc

A binding of File for PNG image.

func Svg

func Svg(b []byte, f string) http.HandlerFunc

A binding of File for SVG image.

http.HandleFunc("/icon.svg", static.Svg(nil, "front/icon.svg"))

func SvgMinify

func SvgMinify(in []byte) []byte

func Template

func Template(b []byte, f string, min Minifier) *templatetext.Template

Create template from b or the file f.

func TemplateHTML

func TemplateHTML(b []byte, f string) *templatehtml.Template

Create template from b or the file f.

func WebP

func WebP(b []byte, f string) http.HandlerFunc

A binding of File for WebP image.

Types

type Minifier

type Minifier func([]byte) []byte

Jump to

Keyboard shortcuts

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