Skip to content

HuguesGuilleus/static.v1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
	}
}

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages