static

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: BSD-3-Clause Imports: 16 Imported by: 1

README

static.v3

PkgGoDev

Create easily a http Handler for static file.

Installation

go get github.com/HuguesGuilleus/static.v3

Example

package main

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

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

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

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

Documentation

Overview

Create easily a http Handler for static file.

Index

Constants

This section is empty.

Variables

View Source
var (
	Log = log.New(os.Stderr, "[STATIC ERROR] ", log.LstdFlags)
	// Dev disable the minifing and read the file at for each request.
	Dev bool = false
)

Functions

func CssMinify

func CssMinify(in []byte) []byte

func HtmlMinify

func HtmlMinify(in []byte) []byte

func JsMinify

func JsMinify(in []byte) []byte

func SvgMinify

func SvgMinify(in []byte) []byte

Types

type Minifier

type Minifier func([]byte) []byte

type Server

type Server struct {
	Body   []byte
	Mime   string
	Minify Minifier
	// contains filtered or unexported fields
}

func Css

func Css() *Server

A binding of File for Css file.

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

func Html

func Html() *Server

A binding of File for Html file.

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

func Jpeg

func Jpeg() *Server

A binding of File for JPEG image.

func Js

func Js() *Server

A binding of File for Js file.

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

func New

func New(mime string, min Minifier) *Server

func Png

func Png() *Server

A binding of File for PNG image.

func SVG

func SVG() *Server

A binding of File for SVG image.

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

func WebP

func WebP() *Server

A binding of File for WebP image.

func (*Server) Bytes

func (s *Server) Bytes(body []byte) *Server

Replace s.Body by minifed (not in dev mode) body.

func (*Server) FS

func (s *Server) FS(fs fs.FS) *Server

func (*Server) File

func (s *Server) File(path string) *Server

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 (*Server) FileJoinPath

func (s *Server) FileJoinPath(path ...string) *Server

Like Server.File() but with a splietd path

func (*Server) Func

func (s *Server) Func(f func() []byte) *Server

Call f once to get s.Body.

In developpement mode, call f for each request.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Template

type Template struct {
	T *template.Template
	// contains filtered or unexported fields
}

Can be breaken

func NewTemplate

func NewTemplate() *Template

func (*Template) Bytes

func (t *Template) Bytes(in []byte) *Template

func (*Template) Execute

func (t *Template) Execute(w io.Writer, data interface{}) error

func (*Template) File

func (t *Template) File(f string) *Template

func (*Template) FileJoinPath

func (t *Template) FileJoinPath(path ...string) *Template

func (*Template) Func

func (t *Template) Func(f func() []byte) *Template

Jump to

Keyboard shortcuts

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