httpservefile

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 12 Imported by: 1

README

Sample HTTPd

Build binary for sample HTTP server:

go build -o sample-httpd github.com/yinyin/go-util-http-serve-file/sample

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyContentStoragePath = errors.New("content storage path is not given")

ErrEmptyContentStoragePath indicate path to content storage is empty.

Functions

This section is empty.

Types

type HTTPFileServer

type HTTPFileServer interface {
	// ServeHTTP respond content to HTTP request `r` with given targetFileName.
	// The defaultFileName will be use instead if targetFileName is empty.
	ServeHTTP(w http.ResponseWriter, r *http.Request, defaultFileName, targetFileName string)

	// Close free used resources.
	Close() (err error)
}

HTTPFileServer define interface for serving file with HTTP handlers.

type ServeFS added in v0.3.0

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

ServeFS is an implementation of HTTPFileServer with fs.FS as content backend.

func NewServeFS added in v0.3.0

func NewServeFS(fsRef fs.FS, fsPathPrefix string, contentModTime time.Time) (s *ServeFS, err error)

NewServeFS create an instance of ServeFS with fsRef, fsPathPrefix and contentModTime.

func NewServeFSWithPrefix added in v0.3.0

func NewServeFSWithPrefix(
	urlPathPrefix string,
	fsRef fs.FS, fsPathPrefix string, contentModTime time.Time) (s *ServeFS, err error)

NewServeFSWithPrefix create an instance of ServeFS with urlPathPrefix, fsRef, fsPathPrefix and contentModTime.

** CAUTION **: Prefix of URL path will NOT be check. Make sure such check is done at routing logic.

func NewServeFSWithPrefixLength added in v0.3.0

func NewServeFSWithPrefixLength(
	urlPathPrefixLen int,
	fsRef fs.FS, fsPathPrefix string,
	contentModTime time.Time) (s *ServeFS, err error)

NewServeFSWithPrefixLength create an instance of ServeFS with urlPathPrefixLen, fsRef, fsPathPrefix and contentModTime.

func (*ServeFS) Close added in v0.3.0

func (s *ServeFS) Close() (err error)

Close free used resources.

func (*ServeFS) ServeHTTP added in v0.3.0

func (s *ServeFS) ServeHTTP(w http.ResponseWriter, r *http.Request, defaultFileName, targetFileName string)

type ServeFileSystem

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

ServeFileSystem is an implementation of HTTPFileServer with file system as content backend.

func NewServeFileSystem

func NewServeFileSystem(contentFolderPath string) (s *ServeFileSystem, err error)

NewServeFileSystem create an instance of ServeFileSystem with contentFolderPath.

func NewServeFileSystemWithPrefix

func NewServeFileSystemWithPrefix(urlPathPrefix, contentFolderPath string) (s *ServeFileSystem, err error)

NewServeFileSystemWithPrefix create an instance of ServeFileSystem with urlPathPrefix and contentFolderPath.

** CAUTION **: Prefix of URL path will NOT be check. Make sure such check is done at routing logic.

func NewServeFileSystemWithPrefixLength

func NewServeFileSystemWithPrefixLength(urlPathPrefixLen int, contentFolderPath string) (s *ServeFileSystem, err error)

NewServeFileSystemWithPrefixLength create an instance of ServeFileSystem with urlPathPrefixLen and contentFolderPath.

func (*ServeFileSystem) Close

func (s *ServeFileSystem) Close() (err error)

Close free used resources.

func (*ServeFileSystem) ServeHTTP

func (s *ServeFileSystem) ServeHTTP(w http.ResponseWriter, r *http.Request, defaultFileName, targetFileName string)

type ServeZipArchive

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

ServeZipArchive is an implementation of HTTPFileServer with a zip file as content backend.

func NewServeZipArchive

func NewServeZipArchive(zipFilePath, zipPathPrefix, zipDefaultContentPath string) (s *ServeZipArchive, err error)

NewServeZipArchive create an instance of ServeFileSystem with zipFilePath, zipPathPrefix and zipDefaultContentPath.

func NewServeZipArchiveWithPrefix

func NewServeZipArchiveWithPrefix(urlPathPrefix, zipFilePath, zipPathPrefix, zipDefaultContentPath string) (s *ServeZipArchive, err error)

NewServeZipArchiveWithPrefix create an instance of ServeZipArchive with urlPathPrefix, zipFilePath, zipPathPrefix and zipDefaultContentPath.

** CAUTION **: Prefix of URL path will NOT be check. Make sure such check is done at routing logic.

func NewServeZipArchiveWithPrefixLength

func NewServeZipArchiveWithPrefixLength(urlPathPrefixLen int, zipFilePath, zipPathPrefix, zipDefaultContentPath string) (s *ServeZipArchive, err error)

NewServeZipArchiveWithPrefixLength create an instance of ServeZipArchive with urlPathPrefixLen, zipFilePath, zipPathPrefix and zipDefaultContentPath.

func (*ServeZipArchive) Close

func (s *ServeZipArchive) Close() (err error)

Close free used resources.

func (*ServeZipArchive) ServeHTTP

func (s *ServeZipArchive) ServeHTTP(w http.ResponseWriter, r *http.Request, defaultFileName, targetFileName string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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