conn, err := net.Dial("tcp", "golang.org:80") if err != nil { log.Fatal(err) } defer conn.Close()
func handleConnection(conn net.Conn) { defer conn.Close() // handle incoming data from conn }In this example, a function `handleConnection` is defined that takes a TCP connection as a parameter. The connection is closed using `defer conn.Close()` at the end of the function. This allows for the connection to be automatically closed when the function completes. Package Library: net