fileserver

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileServer

type FileServer struct {
	Root          string
	ListDirectory bool
}

FileServer serves file

Example

Enable directory listings by setting ListDirectory on the FileServer value instead of using the New constructor. With it off (the default), a request for a directory falls through to the next handler rather than listing it.

package main

import (
	"github.com/moonrhythm/parapet"
	"github.com/moonrhythm/parapet/pkg/fileserver"
)

func main() {
	s := parapet.New()
	s.Use(&fileserver.FileServer{
		Root:          "/srv/downloads",
		ListDirectory: true,
	})
}

func New

func New(root string) *FileServer

New creates new file server

Example

Serve static files from a directory. A request that matches no file falls through to the next middleware in the chain, so put fileserver near the end to use it as a static-file layer in front of an application handler.

package main

import (
	"github.com/moonrhythm/parapet"
	"github.com/moonrhythm/parapet/pkg/fileserver"
)

func main() {
	s := parapet.New()
	s.Use(fileserver.New("/var/www/public"))
	// s.Use(...) — handles requests for paths with no matching file.
}

func (FileServer) ServeHandler

func (m FileServer) ServeHandler(h http.Handler) http.Handler

ServeHandler implements middleware interface

Jump to

Keyboard shortcuts

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