mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
chore: more refactoring and cleanup
This commit is contained in:
parent
aecb56971d
commit
844ce3c3e0
3 changed files with 29 additions and 33 deletions
|
|
@ -36,7 +36,21 @@ func NewClient[T Client](opts ...func(T)) T {
|
|||
return *client
|
||||
}
|
||||
|
||||
func WithCertPool(client Client, certPool *x509.CertPool) error {
|
||||
func LoadCertificateFromPath(client Client, path string) error {
|
||||
cacert, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read certificate at path: %s", path)
|
||||
}
|
||||
certPool := x509.NewCertPool()
|
||||
certPool.AppendCertsFromPEM(cacert)
|
||||
err = LoadCertificateFromPool(client, certPool)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not initialize certificate from pool: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func LoadCertificateFromPool(client Client, certPool *x509.CertPool) error {
|
||||
// make sure we have a valid cert pool
|
||||
if certPool == nil {
|
||||
return fmt.Errorf("invalid cert pool")
|
||||
|
|
@ -63,16 +77,6 @@ func WithCertPool(client Client, certPool *x509.CertPool) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func WithSecureTLS(client Client, certPath string) error {
|
||||
cacert, err := os.ReadFile(certPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read certificate from path '%s': %v", certPath, err)
|
||||
}
|
||||
certPool := x509.NewCertPool()
|
||||
certPool.AppendCertsFromPEM(cacert)
|
||||
return WithCertPool(client, certPool)
|
||||
}
|
||||
|
||||
// Post() is a simplified wrapper function that packages all of the
|
||||
// that marshals a mapper into a JSON-formatted byte array, and then performs
|
||||
// a request to the specified URL.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue