1 // Package static provides a handler for serving static assets from an in-memory
11 // use start time as a conservative bound for last-modified
12 var lastMod = time.Now()
15 Assets map[string]string
17 // Index is the name of an entry in Assets that should be used if the request
18 // path is empty (equivalent to requesting "/"). This is analogous to index
19 // documents commonly used in webservers. If Index is empty, it will be
23 // Default is the name of an entry in Assets that should be used if the
24 // the requested path does not exist in Assets. This is useful for
25 // delivering a common document (usually a frontend application script) that
26 // handles URL-based state on the client side. If Default is empty, it will be
31 func (h Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
32 output, ok := h.Assets[r.URL.Path]
33 if !ok && r.URL.Path == "" && h.Index != "" {
34 output = h.Assets[h.Index]
35 } else if !ok && h.Default != "" {
36 output = h.Assets[h.Default]
42 // Some autogenerated documentation uses frames, e.g. Javadoc
43 rw.Header().Set("X-Frame-Options", "SAMEORIGIN")
45 http.ServeContent(rw, r, r.URL.Path, lastMod, strings.NewReader(output))