zhttp

package
v0.11.7 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRangeSupport       = errors.New("remote server doesn't support seeking")
	ErrUnsupportedRangeType = errors.New("unsupported range type")
	ErrNegativeSeek         = errors.New("cannot seek below 0")
	ErrExceededLength       = errors.New("exceeded content size")
	ErrNoWrite              = errors.New("unable to write to http server")
)

Functions

func BadRequest added in v0.9.1

func BadRequest(w http.ResponseWriter, msg string)

Encode StatusBadRequest with optional msg

func DecodeRequestBody added in v0.8.12

func DecodeRequestBody(dest interface{}, r *http.Request) error

Decode the body into a struct using the Content-Type header

func InternalServerError added in v0.9.1

func InternalServerError(w http.ResponseWriter, msg string)

Encode StatusInternalServerError with optional msg

func Json added in v0.9.0

func Json(w http.ResponseWriter, value interface{}, status int)

Encode the body as json

func MultipartUpload added in v0.9.1

func MultipartUpload(maxSize int64, allowedTypes []string, handler MultipartHandler) http.HandlerFunc

Process multipart upload

func WithError added in v0.9.20

func WithError(handler func(w http.ResponseWriter, r *http.Request) error) http.HandlerFunc

Types

type DirCache added in v0.8.1

type DirCache struct {
	CacheDuration time.Duration
	// contains filtered or unexported fields
}

func NewDirCache added in v0.8.1

func NewDirCache(dir string, duration time.Duration) *DirCache

func (*DirCache) Create added in v0.8.1

func (c *DirCache) Create(key string) (w io.WriteCloser, err error)

func (*DirCache) Has added in v0.8.1

func (c *DirCache) Has(key string) bool

func (*DirCache) Open added in v0.8.1

func (c *DirCache) Open(key string) (r io.ReadCloser, err error)

func (*DirCache) Remove added in v0.8.1

func (c *DirCache) Remove(key string) (err error)

type HttpFile

type HttpFile struct {
	Url       string
	Requests  uint64
	ReadBytes uint64

	ContentType  string
	ContentSize  int64
	RangeSupport bool
	ModTime      time.Time

	io.ReadSeekCloser
	io.ReaderAt
	// contains filtered or unexported fields
}

func NewHttpFile

func NewHttpFile(url string) *HttpFile

func (*HttpFile) Close

func (f *HttpFile) Close() error

func (*HttpFile) Name

func (f *HttpFile) Name() string

func (*HttpFile) Open

func (f *HttpFile) Open() (err error)

func (*HttpFile) Read

func (f *HttpFile) Read(p []byte) (n int, err error)

func (*HttpFile) ReadAt

func (f *HttpFile) ReadAt(p []byte, offset int64) (n int, err error)

func (*HttpFile) Readdir

func (f *HttpFile) Readdir(count int) ([]fs.FileInfo, error)

func (*HttpFile) Readdirnames

func (f *HttpFile) Readdirnames(count int) ([]string, error)

func (*HttpFile) Seek

func (f *HttpFile) Seek(offset int64, whence int) (int64, error)

func (*HttpFile) SetClient

func (f *HttpFile) SetClient(client *http.Client)

func (*HttpFile) Stat

func (f *HttpFile) Stat() (fs.FileInfo, error)

func (*HttpFile) Sync

func (f *HttpFile) Sync() error

func (*HttpFile) Truncate

func (f *HttpFile) Truncate(size int64) error

func (*HttpFile) Write

func (f *HttpFile) Write(p []byte) (int, error)

All write methods unavailable

func (*HttpFile) WriteAt

func (f *HttpFile) WriteAt(p []byte, offset int64) (int, error)

func (*HttpFile) WriteString

func (f *HttpFile) WriteString(str string) (int, error)

type HttpFileInfo

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

func (*HttpFileInfo) IsDir

func (f *HttpFileInfo) IsDir() bool

func (*HttpFileInfo) ModTime

func (f *HttpFileInfo) ModTime() time.Time

func (*HttpFileInfo) Mode

func (f *HttpFileInfo) Mode() fs.FileMode

func (*HttpFileInfo) Name

func (f *HttpFileInfo) Name() string

func (*HttpFileInfo) Size

func (f *HttpFileInfo) Size() int64

func (*HttpFileInfo) Sys

func (f *HttpFileInfo) Sys() interface{}

type MultipartHandler added in v0.9.1

type MultipartHandler = func(w http.ResponseWriter, r *http.Request, file multipart.File, header *multipart.FileHeader) error

type Range

type Range struct {
	Start int
	End   int
	Total int
}

type ReadUnlocker added in v0.8.1

type ReadUnlocker struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

func (*ReadUnlocker) Close added in v0.8.1

func (u *ReadUnlocker) Close() error

type WriteUnlocker added in v0.8.1

type WriteUnlocker struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

func (*WriteUnlocker) Close added in v0.8.1

func (u *WriteUnlocker) Close() error

Jump to

Keyboard shortcuts

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