// example 1 - append a single certificate from a PEM encoded string certPEM := ` -----BEGIN CERTIFICATE----- MIIB6jCCAVOgAwIBAgIQGRnpZMiQg4B0... -----END CERTIFICATE----- ` pool := x509.NewCertPool() pool.AppendCertsFromPEM([]byte(certPEM))
// example 2 - append multiple certificates from a PEM encoded file certFile, err := os.Open("certificates.pem") if err != nil { log.Fatal(err) } defer certFile.Close() pool := x509.NewCertPool() pool.AppendCertsFromPEM(certFile)In example 1, we create a new certificate pool and append a single certificate that is supplied as a PEM-encoded string. In example 2, we open a file containing multiple PEM-encoded certificates, create a new certificate pool, and append all the certificates to the pool. The `AppendCertsFromPEM()` function is a part of the `CertPool` struct, which is defined in the `crypto/x509` package.