The following code works for me:
func setupTLSConnection() (*grpc.ClientConn, error) {
b, err := ioutil.ReadFile("tls/ca.crt")
if err != nil {
return nil, err
}
cp := x509.NewCertPool()
if !cp.AppendCertsFromPEM(b) {
return nil, errors.New("credentials: failed to append certificates")
}
cert, err := tls.LoadX509KeyPair("tls/client.acl.crt", "tls/client.acl.key")
if err != nil {
return nil, err
}
config := &tls.Config{
InsecureSkipVerify: false,
RootCAs: cp,
Certificates: []tls.Certificate{cert},
}
conn, err := grpc.Dial("localhost:9180", grpc.WithTransportCredentials(credentials.NewTLS(config)))
if err != nil {
return nil, err
}
return conn, nil
}
Let me know if you have any more questions.