func Get(program ProgramFunc, serverURL string) (*credentials.Credentials, error) {
	cmd := program("get")
	cmd.Input(strings.NewReader(serverURL))
	out, err := cmd.Output()
	if err != nil {
		t := strings.TrimSpace(string(out))
		if credentials.IsErrCredentialsNotFoundMessage(t) {
			return nil, credentials.NewErrCredentialsNotFound()
		}
		if isValidErr := isValidCredsMessage(t); isValidErr != nil {
			err = isValidErr
		}
		return nil, fmt.Errorf("error getting credentials - err: %v, out: `%s`", err, t)
	}
	resp := &credentials.Credentials{
		ServerURL: serverURL,
	}
	if err := json.NewDecoder(bytes.NewReader(out)).Decode(resp); err != nil {
		return nil, err
	}
	return resp, nil
}
Get executes an external program to get the credentials from a native store.
package client
import (
	"bytes"
	"encoding/json"
	"fmt"
	"strings"
	"github.com/docker/docker-credential-helpers/credentials"
)
func isValidCredsMessage(msg string) error {
	if credentials.IsCredentialsMissingServerURLMessage(msg) {
		return credentials.NewErrCredentialsMissingServerURL()
	}
	if credentials.IsCredentialsMissingUsernameMessage(msg) {
		return credentials.NewErrCredentialsMissingUsername()
	}
	return nil
}
func Store(program ProgramFunc, creds *credentials.Credentials) error {
	cmd := program("store")
	buffer := new(bytes.Buffer)
	if err := json.NewEncoder(buffer).Encode(creds); err != nil {
		return err
	}
	cmd.Input(buffer)
	out, err := cmd.Output()
	if err != nil {
		t := strings.TrimSpace(string(out))
		if isValidErr := isValidCredsMessage(t); isValidErr != nil {
			err = isValidErr
		}
		return fmt.Errorf("error storing credentials - err: %v, out: `%s`", err, t)
	}
	return nil
}