Documentation ¶
Index ¶
- func Gen404Candidates(uri string) []string
- func IterContent(handlers []Handler, fn func(uri string, d []byte))
- func IterURLS(handlers []Handler, withContent bool, fn func(uri string, d []byte))
- func MakeServeContent(uri string, d []byte, code int, modTime time.Time) func(w http.ResponseWriter, r *http.Request)
- func WriteServerFilesToDir(dir string, handlers []Handler, onWritten func(path string, d []byte)) error
- func WriteServerFilesToZip(handlers []Handler, onWritten func(path string, d []byte)) ([]byte, error)
- type DirHandler
- type DynamicHandler
- type EmbedFSHandler
- type FileWriter
- type FilesHandler
- type GetHandlerFunc
- type Handler
- type HandlerFunc
- type InMemoryFilesHandler
- type Server
- type ZipHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Gen404Candidates ¶
func IterContent ¶
IterContent calls a function for every url and its content
func MakeServeContent ¶
func WriteServerFilesToDir ¶
Types ¶
type DirHandler ¶
type DirHandler struct { Dir string URLPrefix string TryServeCompressed bool URL []string // contains filtered or unexported fields }
func NewDirHandler ¶
func NewDirHandler(dir string, urlPrefix string, acceptFile func(string) bool) *DirHandler
func (*DirHandler) Get ¶
func (h *DirHandler) Get(url string) func(w http.ResponseWriter, r *http.Request)
func (*DirHandler) URLS ¶
func (h *DirHandler) URLS() []string
type DynamicHandler ¶
type DynamicHandler struct {
// contains filtered or unexported fields
}
func NewDynamicHandler ¶
func NewDynamicHandler(get GetHandlerFunc, urls func() []string) *DynamicHandler
func (*DynamicHandler) Get ¶
func (h *DynamicHandler) Get(uri string) func(http.ResponseWriter, *http.Request)
func (*DynamicHandler) URLS ¶
func (h *DynamicHandler) URLS() []string
type EmbedFSHandler ¶
type EmbedFSHandler struct { URLPrefix string // contains filtered or unexported fields }
func NewEmbedFSHandler ¶
func NewEmbedFSHandler(fsys embed.FS, dirPrefix, urlPrefix string) *EmbedFSHandler
func (*EmbedFSHandler) Get ¶
func (h *EmbedFSHandler) Get(uri string) func(w http.ResponseWriter, r *http.Request)
func (*EmbedFSHandler) URLS ¶
func (h *EmbedFSHandler) URLS() []string
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
FileWriter implements http.ResponseWriter interface for writing to a io.Writer
func (*FileWriter) Header ¶
func (w *FileWriter) Header() http.Header
func (*FileWriter) WriteHeader ¶
func (w *FileWriter) WriteHeader(statusCode int)
type FilesHandler ¶
type FilesHandler struct { TryServeCompressed bool // contains filtered or unexported fields }
func NewFilesHandler ¶
func NewFilesHandler(files ...string) *FilesHandler
files is: uri1, path1, uri2, path2, ...
func (*FilesHandler) AddFile ¶
func (h *FilesHandler) AddFile(uri, path string)
func (*FilesHandler) AddFilesInDir ¶
func (h *FilesHandler) AddFilesInDir(dir string, uriPrefix string, files []string)
func (*FilesHandler) Get ¶
func (h *FilesHandler) Get(url string) func(w http.ResponseWriter, r *http.Request)
func (*FilesHandler) URLS ¶
func (h *FilesHandler) URLS() []string
type GetHandlerFunc ¶
type GetHandlerFunc = func(string) func(w http.ResponseWriter, r *http.Request)
type Handler ¶
type Handler interface { // returns a handler for this url // if nil, doesn't handle this url Get(url string) HandlerFunc // get all urls handled by this Handler // useful for e.g. saving a static copy to disk URLS() []string }
Handler represents one or more urls and their content
type HandlerFunc ¶
type HandlerFunc = func(w http.ResponseWriter, r *http.Request)
type InMemoryFilesHandler ¶
type InMemoryFilesHandler struct {
// contains filtered or unexported fields
}
func NewInMemoryFilesHandler ¶
func NewInMemoryFilesHandler(uri string, d []byte) *InMemoryFilesHandler
func (*InMemoryFilesHandler) Add ¶
func (h *InMemoryFilesHandler) Add(uri string, body []byte)
func (*InMemoryFilesHandler) Get ¶
func (h *InMemoryFilesHandler) Get(uri string) func(http.ResponseWriter, *http.Request)
func (*InMemoryFilesHandler) URLS ¶
func (h *InMemoryFilesHandler) URLS() []string
type Server ¶
type Server struct { Port int Handlers []Handler // if true supports clean urls i.e. /foo will match /foo.html URL CleanURLS bool // if true forces clean urls i.e. /foo.html will redirect to /foo ForceCleanURLS bool }
Server represents all files known to the server
func (*Server) FindHandler ¶
func (s *Server) FindHandler(uri string) (h HandlerFunc, is404 bool)
func (*Server) FindHandlerExact ¶
func (s *Server) FindHandlerExact(uri string) HandlerFunc
type ZipHandler ¶
func NewZipHandler ¶
func NewZipHandler(zipData []byte, urlPrefix string) (*ZipHandler, error)
func (*ZipHandler) Get ¶
func (h *ZipHandler) Get(uri string) func(w http.ResponseWriter, r *http.Request)
func (*ZipHandler) URLS ¶
func (h *ZipHandler) URLS() []string
Click to show internal directories.
Click to hide internal directories.