modhandler

package module
v0.0.0-...-3f7dc19 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2015 License: MIT Imports: 3 Imported by: 0

README

go-modhandler

A library that provides a ("middleware") HTTP handler to deal with conditional GETs by sending out a "Last-Modified" HTTP response header, and properly dealing with a "If-Modified-Since" HTTP request header, for the Go programming language.

Example

For example:

func ServerHTTP(w http.ResponseWriter, r *http.Request) {

    modtime := ... //@TODO: This is where you figure out the date time for this.
                   //       For example: the modification date of a file, or
                   //       the "when_updated" column in a database, or something.

    modhandler.LastModifiedServeHTTP(w, r, modtime, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){

        //@TODO: Put your "real" ServerHTTP() code in here.
        //
        // Note that a "Last-Modified" header will automagically have been added
        // to the 'w' parameter in this func.
        //
        // But this inner-func will only be call if a conditional GET did not
        // get responded to with a "304 Not Modified" HTTP response.

    }))

}

Documention

Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-modhandler

GoDoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LastModified

func LastModified(modtime time.Time, subhandler http.Handler) http.Handler

LastModified replies to the HTTP request in such a way that it deals with conditional GETs by sending out a "Last-Modified" HTTP response header, and properly dealing with a "If-Modified-Since" HTTP request header.

Note that this request an http.Handler. You will still need to call the returned handler's ServerHTTP method.

func LastModifiedServeHTTP

func LastModifiedServeHTTP(w http.ResponseWriter, r *http.Request, modtime time.Time, subhandler http.Handler)

LastModifiedServeHTTP is similar to the LastModified func, expect that instead of returning a handler, it creates the handle and then immediately calls its ServerHTTP method.

Types

This section is empty.

Jump to

Keyboard shortcuts

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