Issue with go client and self signed certificates

I’ve created a cluster with self signed certs. dashboards is connecting fine, and I can use curl to connect to the cluster fine like so: curl --cacert /path/to/cert
However, when I use the following code:

package main

import (


func main() {
	cert, _ := ioutil.ReadFile("/path/to/cert")
	cfg := elasticsearch.Config{
		Addresses: []string{
		Username: "user",
		Password: "password",
		CACert:   cert,
	es, err := elasticsearch.NewClient(cfg)
	if err != nil {
		log.Fatalf("Error creating the client: %s", err)
	results, err := es.Info()
	if err != nil {
		log.Fatalf("Error getting response: %s", err)
	defer results.Body.Close()


I get the following error: Error getting response: x509: certificate relies on legacy Common Name field, use SANs instead

Can someone help me figure out why this isn’t working? Thanks!