static

package module
v0.0.0-...-55961d6 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: BSD-3-Clause Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

static.v1

GoDoc

Use the new version

Create easily a http.Handler for CSS anf Js files to a Web server.

Installation

go get github.com/HuguesGuilleus/static.v1

Example

Create a directory style and a other js with some files and run the folowing program.

package main

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

func main() {
	// static.Dev = false
	log.Println("go!")
	http.Handle("/style", static.Css("style/"))
	http.Handle("/js", static.Js("js/"))
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Add("Content-type", "text/html; charset=utf-8")
		w.Write([]byte(`<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<link rel="stylesheet" href="/style">
		<script src="/js" charset="utf-8"></script>
	</head>
	<body>
		<p>Hello World!</p>
	</body>
</html>`))
	})
	if err := http.ListenAndServe(":8000", nil); err != nil {
		log.Fatal(err)
	}
}

Documentation

Overview

Create easily a http.Handler for CSS anf Js files to a Web server.

Usage:

http.Handle("/style", static.Css("style/"))
http.Handle("/js", static.Js("js/"))

Index

Constants

This section is empty.

Variables

View Source
var (
	// Dev disable the minifing and reduce the sleeping between two updates.
	Dev bool = false
	// The duration of sleeping in standard mode
	SleepDev time.Duration = 200 * time.Millisecond
	// The duration of sleeping in developpment mode
	SleepProd time.Duration = 10 * time.Minute
)

Functions

func Templ

func Templ(target string) (t *template.Template)

Read target file and return the template, regularly it will be update.

Types

type CssServer

type CssServer []byte

A HTTP server for CSS.

func Css

func Css(directory string) *CssServer

Css create a http.Handler who response with all the CSS file from directory. Regularly the server are update.

func (CssServer) ServeHTTP

func (c CssServer) ServeHTTP(w http.ResponseWriter, _ *http.Request)

type FileServer

type FileServer struct {
	// contains filtered or unexported fields
}

func File

func File(path, mime string) (f *FileServer)

Css create a http.Handler that response with the file from path. The mime can be empty.

func (*FileServer) ServeHTTP

func (f *FileServer) ServeHTTP(w http.ResponseWriter, _ *http.Request)

type HtmlServer

type HtmlServer struct {
	// contains filtered or unexported fields
}

func Html

func Html(path string) (f *HtmlServer)

func (*HtmlServer) ServeHTTP

func (h *HtmlServer) ServeHTTP(w http.ResponseWriter, _ *http.Request)

type JsServer

type JsServer []byte

A HTTP server for Js.

func Js

func Js(directory string) *JsServer

Css create a http.Handler who response with all the Js file from directory. Regularly the server are update.

func (JsServer) ServeHTTP

func (c JsServer) ServeHTTP(w http.ResponseWriter, _ *http.Request)

Jump to

Keyboard shortcuts

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