url

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFileToForm

func AddFileToForm(writer *multipart.Writer, fieldName string, file *File) error

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 BuildURL

func BuildURL(base string, params *Values) (string, error)

func BuildURLFast added in v0.1.0

func BuildURLFast(base string, params map[string]string) (string, error)

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

func BuildURLWithQuery(base string, query url.Values) (string, error)

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

func GetCookies(rawURL string, cookies []*http.Cookie) []*http.Cookie

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

func NewCookies

func NewCookies() *Cookies

NewCookies 创建一个 Cookies 实例

func (*Cookies) Add

func (c *Cookies) Add(cookie *http.Cookie)

Add 添加一个 Cookie

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) Del added in v0.1.0

func (v *FastValues) Del(key string)

Del deletes 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 File

type File struct {
	FileName string
	Reader   io.Reader
}

File represents a file to be uploaded.

func NewFile

func NewFile(filePath string) (*File, error)

NewFile creates a new File from a file path.

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

func (*Headers) Add

func (h *Headers) Add(key, value string)

func (*Headers) Get

func (h *Headers) Get(key string) string

func (*Headers) Set

func (h *Headers) Set(key, value string)

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.

func (*MultipartEncoder) Encode added in v0.1.0

func (me *MultipartEncoder) Encode(w io.Writer) (contentType string, err error)

Encode writes the multipart data to the writer and returns the content type.

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 NewForm

func NewForm() *Values

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.

func NewValues

func NewValues() *Values

func ParseParams added in v0.0.3

func ParseParams(data any) *Values

func (*Values) Add

func (v *Values) Add(key, value string)

============================================================================ Thread-safe Values methods (original) ============================================================================

func (*Values) Del

func (v *Values) Del(key string)

func (*Values) Encode

func (v *Values) Encode() string

func (*Values) Get

func (v *Values) Get(key string) string

func (*Values) GetAll

func (v *Values) GetAll(key string) []string

func (*Values) Keys

func (v *Values) Keys() []string

func (*Values) Merge

func (v *Values) Merge(other *Values)

func (*Values) Reset added in v0.1.0

func (v *Values) Reset()

Reset clears the Values for reuse.

func (*Values) Set

func (v *Values) Set(key, value string)

func (*Values) Values

func (v *Values) Values() map[string][]string

Jump to

Keyboard shortcuts

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