Documentation
¶
Index ¶
- func AddFileToForm(writer *multipart.Writer, fieldName string, file *File) error
- func AddFileUploadToForm(writer *multipart.Writer, upload *FileUpload) error
- func BuildURL(base string, params *Values) (string, error)
- func BuildURLFast(base string, params map[string]string) (string, error)
- func BuildURLWithQuery(base string, query url.Values) (string, error)
- func FastBuildURL(base string, params *FastValues) (string, error)
- func GetCookies(rawURL string, cookies []*http.Cookie) []*http.Cookie
- func ReleaseFastValues(v *FastValues)
- func ReleaseURLParams(v *Values)
- func ReleaseURLParamsUnsafe(v *FastValues)
- func ReleaseValues(v *Values)
- type Cookies
- type FastValues
- func (v *FastValues) Add(key, value string)
- func (v *FastValues) Del(key string)
- func (v *FastValues) Encode() string
- func (v *FastValues) Get(key string) string
- func (v *FastValues) GetAll(key string) []string
- func (v *FastValues) Has(key string) bool
- func (v *FastValues) Keys() []string
- func (v *FastValues) Len() int
- func (v *FastValues) Reset()
- func (v *FastValues) Set(key, value string)
- func (v *FastValues) ToURLValues() url.Values
- func (v *FastValues) Values() map[string][]string
- type File
- type FileUpload
- type Headers
- type MultipartEncoder
- type ProgressCallback
- type ProgressReader
- type Values
- func (v *Values) Add(key, value string)
- func (v *Values) Del(key string)
- func (v *Values) Encode() string
- func (v *Values) Get(key string) string
- func (v *Values) GetAll(key string) []string
- func (v *Values) Keys() []string
- func (v *Values) Merge(other *Values)
- func (v *Values) Reset()
- func (v *Values) Set(key, value string)
- func (v *Values) Values() map[string][]string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddFileToForm ¶
AddFileToForm adds a file to a multipart form writer.
func AddFileUploadToForm ¶ added in v0.1.0
func AddFileUploadToForm(writer *multipart.Writer, upload *FileUpload) error
AddFileUploadToForm adds a FileUpload to a multipart form writer with optional progress tracking.
func BuildURLFast ¶ added in v0.1.0
BuildURLFast builds a URL with query parameters from a map for maximum performance. Avoids intermediate allocations by building the query string directly.
func BuildURLWithQuery ¶ added in v0.1.0
BuildURLWithQuery builds a URL with query parameters from url.Values.
func FastBuildURL ¶ added in v0.1.0
func FastBuildURL(base string, params *FastValues) (string, error)
FastBuildURL builds a URL with query parameters using FastValues for better performance. This is optimized for single-threaded scenarios.
func GetCookies ¶
GetCookies 获取指定 URL 的 Cookies
func ReleaseFastValues ¶ added in v0.1.0
func ReleaseFastValues(v *FastValues)
ReleaseFastValues returns a FastValues to the pool.
func ReleaseURLParams ¶ added in v0.1.0
func ReleaseURLParams(v *Values)
ReleaseURLParams returns a thread-safe Values to the pool.
func ReleaseURLParamsUnsafe ¶ added in v0.1.0
func ReleaseURLParamsUnsafe(v *FastValues)
ReleaseURLParamsUnsafe returns a non-thread-safe FastValues to the pool.
func ReleaseValues ¶ added in v0.1.0
func ReleaseValues(v *Values)
ReleaseValues returns a thread-safe Values to the pool.
Types ¶
type Cookies ¶
type Cookies struct {
// contains filtered or unexported fields
}
Cookies 管理 HTTP Cookies
type FastValues ¶ added in v0.1.0
type FastValues struct {
// contains filtered or unexported fields
}
============================================================================ FastValues - Lock-free version for single-threaded scenarios ============================================================================ FastValues is a high-performance, non-thread-safe URL values container. Use this when you don't need concurrent access for better performance.
func AcquireFastValues ¶ added in v0.1.0
func AcquireFastValues() *FastValues
AcquireFastValues gets a FastValues from the pool.
func AcquireURLParamsUnsafe ¶ added in v0.1.0
func AcquireURLParamsUnsafe() *FastValues
AcquireURLParamsUnsafe gets a non-thread-safe FastValues from the pool. Remember to call ReleaseURLParamsUnsafe when done.
WARNING: This is NOT safe for concurrent access. Use AcquireURLParams for thread-safe operations.
func NewFastValues ¶ added in v0.1.0
func NewFastValues() *FastValues
NewFastValues creates a new FastValues instance.
func NewURLParamsUnsafe ¶ added in v0.1.0
func NewURLParamsUnsafe() *FastValues
NewURLParamsUnsafe creates a new non-thread-safe FastValues for URL parameters. This provides better performance in single-threaded scenarios by avoiding lock overhead.
WARNING: This is NOT safe for concurrent access. Use NewURLParams for thread-safe operations.
func (*FastValues) Add ¶ added in v0.1.0
func (v *FastValues) Add(key, value string)
Add adds a value to the key.
func (*FastValues) Encode ¶ added in v0.1.0
func (v *FastValues) Encode() string
Encode encodes the values to a URL query string. Uses pre-allocated buffer for better performance.
func (*FastValues) Get ¶ added in v0.1.0
func (v *FastValues) Get(key string) string
Get returns the first value for the key.
func (*FastValues) GetAll ¶ added in v0.1.0
func (v *FastValues) GetAll(key string) []string
GetAll returns all values for the key.
func (*FastValues) Has ¶ added in v0.1.0
func (v *FastValues) Has(key string) bool
Has returns true if the key exists.
func (*FastValues) Keys ¶ added in v0.1.0
func (v *FastValues) Keys() []string
Keys returns all keys.
func (*FastValues) Len ¶ added in v0.1.0
func (v *FastValues) Len() int
Len returns the number of keys.
func (*FastValues) Reset ¶ added in v0.1.0
func (v *FastValues) Reset()
Reset clears the FastValues for reuse.
func (*FastValues) Set ¶ added in v0.1.0
func (v *FastValues) Set(key, value string)
Set sets the key to a single value.
func (*FastValues) ToURLValues ¶ added in v0.1.0
func (v *FastValues) ToURLValues() url.Values
ToURLValues converts to standard url.Values.
func (*FastValues) Values ¶ added in v0.1.0
func (v *FastValues) Values() map[string][]string
Values returns a copy of the underlying data.
type FileUpload ¶ added in v0.1.0
type FileUpload struct {
FieldName string
FileName string
Reader io.Reader
Size int64
Progress ProgressCallback
}
FileUpload represents a file upload with optional progress tracking.
func NewFileUpload ¶ added in v0.1.0
func NewFileUpload(fieldName, filePath string) (*FileUpload, error)
NewFileUpload creates a FileUpload from a file path.
func NewFileUploadFromReader ¶ added in v0.1.0
func NewFileUploadFromReader(fieldName, fileName string, reader io.Reader, size int64) *FileUpload
NewFileUploadFromReader creates a FileUpload from an io.Reader.
func (*FileUpload) WithProgress ¶ added in v0.1.0
func (fu *FileUpload) WithProgress(callback ProgressCallback) *FileUpload
WithProgress sets a progress callback for the file upload.
type Headers ¶
type Headers struct {
// contains filtered or unexported fields
}
func NewHeaders ¶
func NewHeaders() *Headers
type MultipartEncoder ¶ added in v0.1.0
type MultipartEncoder struct {
// contains filtered or unexported fields
}
MultipartEncoder encodes multiple files and form fields into multipart format.
func NewMultipartEncoder ¶ added in v0.1.0
func NewMultipartEncoder() *MultipartEncoder
NewMultipartEncoder creates a new MultipartEncoder.
func (*MultipartEncoder) AddField ¶ added in v0.1.0
func (me *MultipartEncoder) AddField(name, value string) *MultipartEncoder
AddField adds a form field to the encoder.
func (*MultipartEncoder) AddFile ¶ added in v0.1.0
func (me *MultipartEncoder) AddFile(upload *FileUpload) *MultipartEncoder
AddFile adds a file to the encoder.
type ProgressCallback ¶ added in v0.1.0
type ProgressCallback func(uploaded, total int64)
ProgressCallback is called during file upload to report progress.
type ProgressReader ¶ added in v0.1.0
type ProgressReader struct {
// contains filtered or unexported fields
}
ProgressReader wraps an io.Reader to track read progress.
func NewProgressReader ¶ added in v0.1.0
func NewProgressReader(reader io.Reader, total int64, callback ProgressCallback) *ProgressReader
NewProgressReader creates a new ProgressReader.
func (*ProgressReader) Progress ¶ added in v0.1.0
func (pr *ProgressReader) Progress() (uploaded, total int64)
Progress returns the current upload progress.
func (*ProgressReader) Read ¶ added in v0.1.0
func (pr *ProgressReader) Read(p []byte) (int, error)
Read implements io.Reader interface with progress tracking.
func (*ProgressReader) Reset ¶ added in v0.1.0
func (pr *ProgressReader) Reset()
Reset resets the progress counter.
type Values ¶
type Values struct {
// contains filtered or unexported fields
}
============================================================================ Thread-safe Values (original implementation) ============================================================================
func AcquireURLParams ¶ added in v0.1.0
func AcquireURLParams() *Values
AcquireURLParams gets a thread-safe Values from the pool for URL parameters. Remember to call ReleaseURLParams when done. This combines object pooling with thread-safety for optimal performance in concurrent scenarios.
func AcquireValues ¶ added in v0.1.0
func AcquireValues() *Values
AcquireValues gets a thread-safe Values from the pool. Remember to call ReleaseValues when done.
func NewURLParams ¶
func NewURLParams() *Values
NewURLParams creates a new thread-safe Values for URL parameters. This is the recommended default for most use cases as it provides safe concurrent access using sync.RWMutex.
For high-performance single-threaded scenarios, use NewURLParamsUnsafe instead.