Standard library / net/http
http.Transport.Clone()
Copy exported transport settings without sharing the idle connection pool; change the clone before use. Expected stdout: '4 8\n'.
Formal Syntax & Structure
go syntaxgo
func (t *Transport) Clone() *TransportReturn Value
*Transport
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "net/http")
func main() { tr := &http.Transport{MaxIdleConns: 4} c := tr.Clone() c.MaxIdleConns = 8 fmt.Println(tr.MaxIdleConns, c.MaxIdleConns)}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}