Config
The Config struct provides configuration options for HTTP requests.
Type Definition
go
type Config struct {
URL string
Method string
Headers Headers
Query Query
Params Params
Body Body
BaseURL string
Timeout time.Duration
DownloadFilePath string
Proxy string
IsStream bool
IsSession bool
HTTP2 bool
// TLS Configuration
TLSCaCert []byte
TLSCaCertFile string
TLSCert []byte
TLSCertFile string
TLSKey []byte
TLSKeyFile string
TLSInsecureSkipVerify bool
// Unix Domain Socket
UnixDomainSocket string
// Context
Context context.Context
// Progress Callback
OnProgress OnProgress
// Authentication
BasicAuth BasicAuth
Username string
Password string
}Fields
Request Configuration
URL: The target URL for the requestMethod: HTTP method (GET, POST, PUT, PATCH, DELETE, HEAD)Headers: Request headers mapQuery: Query parameters mapParams: URL path parameters mapBody: Request body (can be map, string, bytes, io.Reader, etc.)BaseURL: Base URL for relative paths
Timeout
Timeout: Request timeout duration
File Operations
DownloadFilePath: Path to save downloaded file
Network
Proxy: Proxy server URL (http, https, socks5)UnixDomainSocket: Unix domain socket pathHTTP2: Enable HTTP/2 support
TLS
TLSCaCert: CA certificate bytesTLSCaCertFile: Path to CA certificate fileTLSCert: Client certificate bytesTLSCertFile: Path to client certificate fileTLSKey: Client private key bytesTLSKeyFile: Path to client private key fileTLSInsecureSkipVerify: Skip TLS certificate verification
Other
IsStream: Enable streaming modeIsSession: Enable session (cookie) managementContext: Context for cancellationOnProgress: Progress callback functionBasicAuth: Basic authentication credentialsUsername: Username for authenticationPassword: Password for authentication
Methods
Merge
Merges another config into this config.
go
func (c *Config) Merge(config *Config)Clone
Creates a clone of the config.
go
func (c *Config) Clone() *ConfigRelated Types
BasicAuth
go
type BasicAuth struct {
Username string
Password string
}OnProgress
Progress callback function type.
go
type OnProgress func(percent int64, current, total int64)Example
go
config := &fetch.Config{
BaseURL: "https://api.example.com",
Timeout: 10 * time.Second,
Headers: map[string]string{
"Authorization": "Bearer token",
"Content-Type": "application/json",
},
Query: map[string]string{
"page": "1",
},
Body: map[string]interface{}{
"name": "John",
},
}
response, err := fetch.Post("/users", config)