v1.0.0 修复其于 http basic auth 的bug
This commit is contained in:
parent
d25b7ff831
commit
fbfb1d80a8
11
goes.go
11
goes.go
@ -34,7 +34,7 @@ func (err *SearchError) Error() string {
|
|||||||
// This function is pretty useless for now but might be useful in a near future
|
// This function is pretty useless for now but might be useful in a near future
|
||||||
// if wee need more features like connection pooling or load balancing.
|
// if wee need more features like connection pooling or load balancing.
|
||||||
func NewClient(host string, port string) *Client {
|
func NewClient(host string, port string) *Client {
|
||||||
return &Client{host, port, http.DefaultClient, ""}
|
return &Client{host, port, http.DefaultClient, "", "", ""}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithHTTPClient sets the http.Client to be used with the connection. Returns the original client.
|
// WithHTTPClient sets the http.Client to be used with the connection. Returns the original client.
|
||||||
@ -585,6 +585,11 @@ func (c *Client) DoRaw(r Requester) ([]byte, uint64, error) {
|
|||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
c.replaceHost(req)
|
c.replaceHost(req)
|
||||||
|
|
||||||
|
if c.AuthUsername != "" {
|
||||||
|
req.SetBasicAuth(c.AuthUsername, c.AuthPassword)
|
||||||
|
}
|
||||||
|
|
||||||
return c.doRequest(req)
|
return c.doRequest(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,6 +601,10 @@ func (c *Client) Do(r Requester) (*Response, error) {
|
|||||||
}
|
}
|
||||||
c.replaceHost(req)
|
c.replaceHost(req)
|
||||||
|
|
||||||
|
if c.AuthUsername != "" {
|
||||||
|
req.SetBasicAuth(c.AuthUsername, c.AuthPassword)
|
||||||
|
}
|
||||||
|
|
||||||
body, statusCode, err := c.doRequest(req)
|
body, statusCode, err := c.doRequest(req)
|
||||||
esResp := &Response{Status: statusCode}
|
esResp := &Response{Status: statusCode}
|
||||||
|
|
||||||
|
@ -43,6 +43,12 @@ type Request struct {
|
|||||||
|
|
||||||
// Used for the id field when indexing a document
|
// Used for the id field when indexing a document
|
||||||
ID string
|
ID string
|
||||||
|
|
||||||
|
// Auth username
|
||||||
|
AuthUsername string
|
||||||
|
|
||||||
|
// Auth password
|
||||||
|
AuthPassword string
|
||||||
}
|
}
|
||||||
|
|
||||||
// URL builds a URL for a Request
|
// URL builds a URL for a Request
|
||||||
|
@ -23,6 +23,12 @@ type Client struct {
|
|||||||
|
|
||||||
// Detected version of ES
|
// Detected version of ES
|
||||||
version string
|
version string
|
||||||
|
|
||||||
|
// user name for http basic auth
|
||||||
|
AuthUsername string `json:"username"`
|
||||||
|
|
||||||
|
// pass word for http basic auth
|
||||||
|
AuthPassword string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response holds an elasticsearch response
|
// Response holds an elasticsearch response
|
||||||
|
Loading…
Reference in New Issue
Block a user