burrow

package module
v0.0.0-...-738e6fc Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2021 License: MIT Imports: 2 Imported by: 0

README

Burrow for gophers.

Toolkit for go net/http.

Install

go get github.com/mkch/burrow
go install github.com/mkch/burrow

Examples

* Compress
package compress_test

import (
    "github.com/mkch/burrow/compress"
    "net/http"
)

func main() {
    http.ListenAndServe(":8080", compress.NewHandler(http.DefaultServeMux, nil))
}
* Session
package session_test

import (
	"github.com/mkch/burrow/session"
	"net/http"
)

var sessionManager = session.NewSessionManager()

func main() {
	http.Handle("/foo", session.HTTPHandlerFunc(fooHandler))
	http.ListenAndServe(":8080", sessionManager.Handler(http.DefaultServeMux))
}

func fooHandler(w http.ResponseWriter, r *http.Request, s session.Session) {
	// Access session value with s.
}
* Status Hook
package statushook_test

import (
	"github.com/mkch/burrow/statushook"
	"net/http"
)

func main() {
	http.HandleFunc("/foo",
		func(w http.ResponseWriter, r *http.Request) {
			w.Write([]byte("This is foo."))
		})

	refined404Hook := func(code int, w http.ResponseWriter, r *http.Request) {
		if code == http.StatusNotFound {
			w.Write([]byte("404 Gohper is not here: "+r.URL.String()))
		}
	}
	handler := statushook.Handler(http.DefaultServeMux, statushook.HookFunc(refined404Hook))
	http.ListenAndServe("localhost:8181", handler)

	// Please access http://localhost:8181/anything-except-foo in your browser
	// to get the refined 404 page:
	//
	//		404 Gohper is not here: /anything-except-foo
}
* Google SPDY™
package spdy_test

import (
	"crypto/tls"
	"github.com/mkch/burrow/spdy"
	"net/http"
)

func main() {
	server := &http.Server{
		Addr: ":8080",
		TLSConfig: &tls.Config{
			NextProtos: []string{"spdy/2"},
		},
		TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){
			"spdy/2": spdy.TLSNextProtoFuncV2,
		},
	}

	http.HandleFunc("/hello", func(w http.ResponseWriter, req *http.Request) {
		w.Write([]byte("Hello, " + req.URL.String()))
		if spdy.Spdy(req) {
			w.Write([]byte(" from SPDY!"))
		}
	})

	server.ListenAndServeTLS("/path/to/host.crt", "/path/to/host.key")
}

Documentation

Overview

Package burrow provides useful utilities that work with net/http package.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dir

type Dir struct {
	http.Dir
	// AllowListDir indicates whether dir listing is allowed.
	AllowListDir bool
}

Type Dir is an enhanced version of http.Dir.

Example
http.FileServer(&Dir{Dir: http.Dir("some/dir")})
Output:

func (*Dir) Open

func (fs *Dir) Open(name string) (f http.File, err error)

Directories

Path Synopsis
Package compress provides http compression implementation with "gzip" and "deflate" content-encodings.
Package compress provides http compression implementation with "gzip" and "deflate" content-encodings.
Package my4040 provides support for setting customized http 404 handler.
Package my4040 provides support for setting customized http 404 handler.
Package session provides HTTP cookie session implementations.
Package session provides HTTP cookie session implementations.
Package spdy implements Google SPDY™ protocol.
Package spdy implements Google SPDY™ protocol.
framing
Package framing implements Google SPDY™ protocol framing layer.
Package framing implements Google SPDY™ protocol framing layer.
framing/fields
Package fields implements wire format decoding and encoding.
Package fields implements wire format decoding and encoding.
Package statushook provides a utility to hook a http.Handler before the status code is written, giving the hook a chance to midify the response header, or replace the entire response.
Package statushook provides a utility to hook a http.Handler before the status code is written, giving the hook a chance to midify the response header, or replace the entire response.

Jump to

Keyboard shortcuts

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