MCPcopy
hub / github.com/gofiber/fiber / SetRootCertificate

Method SetRootCertificate

client/client.go:313–340  ·  view source on GitHub ↗

SetRootCertificate adds one or more root certificates to the client's TLS configuration.

(path string)

Source from the content-addressed store, hash-verified

311
312// SetRootCertificate adds one or more root certificates to the client's TLS configuration.
313func (c *Client) SetRootCertificate(path string) *Client {
314 cleanPath := filepath.Clean(path)
315 file, err := os.Open(cleanPath)
316 if err != nil {
317 c.logger.Panicf("client: %v", err)
318 }
319 defer func() {
320 if closeErr := file.Close(); closeErr != nil {
321 c.logger.Panicf("client: failed to close file: %v", closeErr)
322 }
323 }()
324
325 pem, err := io.ReadAll(file)
326 if err != nil {
327 c.logger.Panicf("client: %v", err)
328 }
329
330 config := c.TLSConfig()
331 if config.RootCAs == nil {
332 config.RootCAs = x509.NewCertPool()
333 }
334
335 if !config.RootCAs.AppendCertsFromPEM(pem) {
336 c.logger.Panicf("client: %v", ErrFailedToAppendCert)
337 }
338
339 return c
340}
341
342// SetRootCertificateFromString adds one or more root certificates from a string to the client's TLS configuration.
343func (c *Client) SetRootCertificateFromString(pem string) *Client {

Calls 3

TLSConfigMethod · 0.95
PanicfMethod · 0.65
CloseMethod · 0.65

Tested by 2