func (f PostFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	resource, location, err := f(getVars(r), r)
	if err != nil {
		writeError(err, w, r)
		return
	}
	if location != "" {
		w.Header().Set("Location", location)
	}
	if resource == nil {
		w.WriteHeader(http.StatusCreated)
		w.Write(noContent)
		return
	}
	writeResource(resource, w, r)
}
ServeHTTP implements the http.Handler interface.
package rst
import (
	"net/http"
	"strings"
	"time"
)
var noContent = []byte{}
type Resource interface {
	ETag() string             
	LastModified() time.Time  
	TTL() time.Duration       
}
func ValidateConditions(resource Resource, r *http.Request) bool {
	if d, err := time.Parse(rfc1123, r.Header.Get("If-Unmodified-Since")); err == nil {
		if d.Sub(resource.LastModified()) < 0 {
			return true
		}
	}
	if etag := r.Header.Get("If-Match"); etag != "" && etag != resource.ETag() {
		return true
	}
	return false
}
type Ranger interface {
	Units() []string
	Count() uint64
	Range(*Range) (*ContentRange, Resource, error)
}
func writeError(err error, w http.ResponseWriter, r *http.Request) {
	ErrorHandler(err).ServeHTTP(w, r)
}
func writeResource(resource Resource, w http.ResponseWriter, r *http.Request) {
	if t, err := time.Parse(rfc1123, r.Header.Get("If-Modified-Since")); err == nil {
		if t.Sub(resource.LastModified()).Seconds() >= 0 {
			w.WriteHeader(http.StatusNotModified)
			w.Write(noContent)
			return
		}
	}
	for _, t := range strings.Split(r.Header.Get("If-None-Match"), ";") {
		if t == resource.ETag() {
			w.WriteHeader(http.StatusNotModified)
			w.Write(noContent)
			return
		}
	}
	addVary(w.Header(), "Accept")
	w.Header().Set("Last-Modified", resource.LastModified().UTC().Format(rfc1123))
	w.Header().Set("ETag", resource.ETag())
	w.Header().Set("Expires", time.Now().Add(resource.TTL()).UTC().Format(rfc1123))
	if handler, implemented := resource.(http.Handler); implemented {
		handler.ServeHTTP(w, r)
		return
	}
	var (
		contentType string
		b           []byte
		err         error
	)
	contentType, b, err = Marshal(resource, r)
	if err != nil {
		writeError(err, w, r)
		return
	}
	w.Header().Set("Content-Type", contentType)
	if compression := getCompressionFormat(b, r); compression != "" {
		w.Header().Set("Content-Encoding", compression)
		addVary(w.Header(), "Accept-Encoding")
	}
	if strings.ToUpper(r.Method) == Post {
		w.WriteHeader(http.StatusCreated)
		w.Write(b)
		return
	}
	if len(b) == 0 {
		w.WriteHeader(http.StatusNoContent)
		w.Write(noContent)  
		return
	}
	if w.Header().Get("Content-Range") != "" {
		w.WriteHeader(http.StatusPartialContent)
	} else {
		w.WriteHeader(http.StatusOK)
	}
	if strings.ToUpper(r.Method) == Head {
		w.Write(noContent)
		return
	}
	w.Write(b)
}
type Endpoint interface{}
type Getter interface {
	Get(RouteVars, *http.Request) (Resource, error)
}
type GetFunc func(RouteVars, *http.Request) (Resource, error)
func (f GetFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	vars := getVars(r)
	resource, err := f(vars, r)
	if err != nil {
		writeError(err, w, r)
		return
	}
	if resource == nil {
		w.WriteHeader(http.StatusNoContent)
		w.Write(noContent)
		return
	}
	ranger, implemented := resource.(Ranger)
	if !implemented {
		writeResource(resource, w, r)
		return
	}
	w.Header().Set("Accept-Ranges", strings.Join(ranger.Units(), ", "))
	rg, err := ParseRange(r.Header.Get("Range"))
	if err != nil || rg.validate(ranger) != nil {
		writeResource(resource, w, r)
		return
	}
	if raw := r.Header.Get("If-Range"); raw != "" {
		date, _ := time.Parse(rfc1123, raw)
		if !date.Equal(resource.LastModified()) && raw != resource.ETag() {
			writeResource(resource, w, r)
			return
		}
	}
	if err := rg.adjust(ranger); err != nil {
		writeError(err, w, r)
		return
	}
	cr, partial, err := ranger.Range(rg)
	if err != nil {
		writeError(err, w, r)
		return
	}
	addVary(w.Header(), "Range")
	w.Header().Set("Content-Range", cr.String())
	writeResource(partial, w, r)
}
type Patcher interface {
	Patch(RouteVars, *http.Request) (Resource, error)
}
type PatchFunc func(RouteVars, *http.Request) (Resource, error)
func (f PatchFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	resource, err := f(getVars(r), r)
	if err != nil {
		writeError(err, w, r)
		return
	}
	w.WriteHeader(http.StatusOK)
	if resource == nil {
		w.Write(noContent)
		return
	}
	writeResource(resource, w, r)
}
type Putter interface {
	Put(RouteVars, *http.Request) (Resource, error)
}
type PutFunc func(RouteVars, *http.Request) (Resource, error)
func (f PutFunc) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	resource, err := f(getVars(r), r)
	if err != nil {
		writeError(err, w, r)
		return
	}
	w.WriteHeader(http.StatusOK)
	if resource == nil {
		w.Write(noContent)
		return
	}
	writeResource(resource, w, r)
}
type Poster interface {
	Post(RouteVars, *http.Request) (resource Resource, location string, err error)
}
type PostFunc func(RouteVars, *http.Request) (Resource, string, error)