// Create a TLS configuration with certificates and server name tlsConfig := &tls.Config{ Certificates: []tls.Certificate{cert}, ServerName: "example.com", } // Dial a server with the TLS configuration conn, err := tls.Dial("tcp", "example.com:443", tlsConfig) if err != nil { log.Fatal("TLS connection error: ", err) } // Print the current connection state state := conn.ConnectionState() fmt.Println("Current state: ", state)
// Create a TLS listener with the TLS configuration listener, err := tls.Listen("tcp", ":443", tlsConfig) if err != nil { log.Fatal("TLS listener error: ", err) } // Accept a new connection and print its current state conn, err := listener.Accept() if err != nil { log.Fatal("TLS accept error: ", err) } state := conn.ConnectionState() fmt.Println("Current state: ", state)In these examples, we first create a TLS configuration with certificates and server name. We then establish a TLS connection or listener using this configuration, and print the current connection state using the ConnectionState struct. The package library for this is "crypto/tls".