fileserve

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: MIT Imports: 19 Imported by: 0

README

fileserve

Build Status Go Reference

Golang-based simple file server to serve static files of the current working directory

  • File sharing in LAN or home network
  • Web application testing
  • Personal web site hosting or demonstrating

Features

  • Directory listing
  • Filter dot files
  • Cors or NoCache headers
  • HTTPS with self-signed certificate
  • BasicAuth
  • Custom HTTP headers

Installing

You can install the pre-compiled binary in several different ways

homebrew tap:
brew tap hupe1980/fileserve
brew install fileserve
snapcraft:

Get it from the Snap Store

sudo snap install fileserve
scoop:
scoop bucket add fileserve https://github.com/hupe1980/fileserve-bucket.git
scoop install fileserve
deb/rpm/apk:

Download the .deb, .rpm or .apk from the releases page and install them with the appropriate tools.

manually:

Download the pre-compiled binaries from the releases page and copy to the desired location.

How to use

fileserve is a tiny go based file server

Usage:
  fileserve [root] [flags]

Examples:
- serve the current working dir: fileserve
- add basic auth: fileserve -a user1:pass1 -a user2:pass2
- add custom http headers: fileserve --header Test=ABC --header Foo=Bar
- disable serving of dot files: fileserve --no-dot

Flags:
  -a, --auth stringArray        turn on basic auth and set username and password (separate by colon)
  -b, --bind string             bind to a specific interface (default "0.0.0.0")
      --cors                    allow cross origin requests to be served
      --header stringToString   add custom http headers (default [])
  -h, --help                    help for fileserve
  -s, --https                   serve with a temp self-signed certificate via HTTPS
      --no-cache                disable caching for the file server
      --no-dir                  turn off directory listing
      --no-dot                  disable serving of dot files
  -p, --port int                port to serve on (default 8000)
  -v, --version                 version for fileserve

Or use the module to create your own portable:

License

MIT

Documentation

Index

Constants

View Source
const DefaultIndexPage = "index.html"
View Source
const DefaultPort = 8000

Variables

This section is empty.

Functions

func AccessLog

func AccessLog() func(next http.Handler) http.Handler

func BasicAuth

func BasicAuth(realm string, creds map[string]string) func(next http.Handler) http.Handler

BasicAuth creates a basic authentication middleware

func CORS

func CORS(origin string) func(next http.Handler) http.Handler

func HTTPHeader

func HTTPHeader(key, value string) func(next http.Handler) http.Handler

HTTPHeader is a handler to set a response header key/value

func NewSelfSignedCert

func NewSelfSignedCert(sans []string) (tls.Certificate, error)

func NoCache

func NoCache() func(next http.Handler) http.Handler

func NoDot added in v0.0.8

func NoDot(err string, code int) func(next http.Handler) http.Handler

Types

type Fileserve

type Fileserve struct {
	// contains filtered or unexported fields
}

func New

func New(root Root, optFns ...func(o *Options)) (*Fileserve, error)

func (*Fileserve) ListenAndServe

func (s *Fileserve) ListenAndServe() error

func (*Fileserve) Use

func (s *Fileserve) Use(middlewares ...func(http.Handler) http.Handler)

type LogEntry

type LogEntry struct {
	// contains filtered or unexported fields
}

func NewLogEntry

func NewLogEntry(r *http.Request) *LogEntry

func (*LogEntry) Write

func (e *LogEntry) Write(status int, header http.Header)

type Options

type Options struct {
	Port int
	Bind string
	TLS  bool
}

type Root added in v0.0.8

type Root interface {
	http.FileSystem
}

func NewDirRoot added in v0.0.7

func NewDirRoot(dir string, optFns ...func(o *RootOptions)) (Root, error)

func NewFSRoot added in v0.0.8

func NewFSRoot(distFS fs.FS, optFns ...func(o *RootOptions)) (Root, error)

type RootOptions added in v0.0.8

type RootOptions struct {
	HideDirListing bool
	HideDotFiles   bool
}

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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