Пример #1
0
func ClientBuilder(connection *Connection, base string) (*BasicClient, error) {
	httpClient := &http.Client{}
	var basicClient *BasicClient
	var digestHeaders *digestAuth.DigestHeaders
	var err error
	if connection.AuthenticationType == DigestAuth {
		digestHeaders = &digestAuth.DigestHeaders{}
		digestHeaders, err = digestHeaders.Auth(connection.Username, connection.Password, base+"/config/resources?format=xml")
	}
	if err == nil {
		basicClient =
			&BasicClient{
				base:          base,
				userinfo:      url.UserPassword(connection.Username, connection.Password),
				authType:      connection.AuthenticationType,
				httpClient:    httpClient,
				digestHeaders: digestHeaders,
			}
	}
	return basicClient, err
}
Пример #2
0
// NewClient creates the Client struct used for searching, etc.
func NewClient(host string, port int64, username string, password string, authType int) (*Client, error) {
	base := "http://" + host + ":" + strconv.FormatInt(port, 10) + "/v1"
	httpClient := &http.Client{}
	var client *Client
	var digestHeaders *digestAuth.DigestHeaders
	var err error
	if authType == DigestAuth {
		digestHeaders = &digestAuth.DigestHeaders{}
		digestHeaders, err = digestHeaders.Auth(username, password, base+"/config/resources?format=xml")
	}
	if err == nil {
		client = &Client{
			&BasicClient{
				base:          base,
				userinfo:      url.UserPassword(username, password),
				authType:      authType,
				httpClient:    httpClient,
				digestHeaders: digestHeaders,
			},
		}
	}
	return client, err
}