httpservefile

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2019 License: MIT Imports: 8 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 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