github.com/blend/go-sdk@v1.20220411.3/certutil/join_pems.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package certutil
     9  
    10  import "strings"
    11  
    12  // JoinPEMs appends pem blocks together with newlines.
    13  //
    14  // Each pem block will have `strings.TrimSpace()` called on it.
    15  //
    16  // Usage note: you should add pems in the following order:
    17  // - leaf
    18  // - intermediate
    19  // - root
    20  // It's a little baffling, basically the other way around from what you'd thing probably.
    21  func JoinPEMs(pems ...string) string {
    22  	var cleaned []string
    23  	for _, pem := range pems {
    24  		pemCleaned := strings.TrimSpace(pem)
    25  		if pemCleaned != "" {
    26  			cleaned = append(cleaned, pemCleaned)
    27  		}
    28  	}
    29  	return strings.Join(cleaned, "\n") + "\n"
    30  }