conn, err := net.Dial("tcp", "example.com:8080") if err != nil { // handle error } l := &net.Linger{ OnOff: true, Seconds: 10, } err = conn.(*net.TCPConn).SetLinger(l) if err != nil { // handle error } // use connection
conn, err := net.Dial("tcp", "example.com:8080") if err != nil { // handle error } l := &net.Linger{ OnOff: false, Seconds: 0, } err = conn.(*net.TCPConn).SetLinger(l) if err != nil { // handle error } // use connectionIn this example, `OnOff` is set to `false`, indicating that `SO_LINGER` should be disabled. `Seconds` is set to `0` (ignored when `OnOff` is `false`). The `SetLinger` method is part of the `net` package in the standard Go library.