code: func MarshalPrivateKeyToPEM(privateKey crypto.PrivateKey) ([]byte, error) {
  	switch t := privateKey.(type) {
  	case *ecdsa.PrivateKey:
  		derBytes, err := x509.MarshalECPrivateKey(t)
  		if err != nil {
  			return nil, err
  		}
  		block := &pem.Block{
  			Type:  ECPrivateKeyBlockType,
  			Bytes: derBytes,
  		}
  		return pem.EncodeToMemory(block), nil
  	case *rsa.PrivateKey:
  		block := &pem.Block{
  			Type:  RSAPrivateKeyBlockType,
  			Bytes: x509.MarshalPKCS1PrivateKey(t),
  		}
  		return pem.EncodeToMemory(block), nil
  	default:
  		return nil, fmt.Errorf("private key is not a recognized type: %T", privateKey)
  	}
  }
docs: // MarshalPrivateKeyToPEM converts a known private key type of RSA or ECDSA to
  // a PEM encoded block or returns an error.