diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-04-16 05:37:14 -0700 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2018-04-16 08:37:14 -0400 |
commit | 6e2cb00008cbf09e556b00f87603797fcaa47e09 (patch) | |
tree | 3c0eb55ff4226a3f024aad373140d1fb860a6404 /vendor/github.com/olivere/elastic/request.go | |
parent | bf24f51c4e1cc6286885460672f7f449e8c6f5ef (diff) | |
download | chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.gz chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.tar.bz2 chat-6e2cb00008cbf09e556b00f87603797fcaa47e09.zip |
Depenancy upgrades and movign to dep. (#8630)
Diffstat (limited to 'vendor/github.com/olivere/elastic/request.go')
-rw-r--r-- | vendor/github.com/olivere/elastic/request.go | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/vendor/github.com/olivere/elastic/request.go b/vendor/github.com/olivere/elastic/request.go deleted file mode 100644 index 87d191965..000000000 --- a/vendor/github.com/olivere/elastic/request.go +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright 2012-present Oliver Eilhard. All rights reserved. -// Use of this source code is governed by a MIT-license. -// See http://olivere.mit-license.org/license.txt for details. - -package elastic - -import ( - "bytes" - "encoding/json" - "io" - "io/ioutil" - "net/http" - "runtime" - "strings" -) - -// Elasticsearch-specific HTTP request -type Request http.Request - -// NewRequest is a http.Request and adds features such as encoding the body. -func NewRequest(method, url string) (*Request, error) { - req, err := http.NewRequest(method, url, nil) - if err != nil { - return nil, err - } - req.Header.Add("User-Agent", "elastic/"+Version+" ("+runtime.GOOS+"-"+runtime.GOARCH+")") - req.Header.Add("Accept", "application/json") - req.Header.Set("Content-Type", "application/json") - return (*Request)(req), nil -} - -// SetBasicAuth wraps http.Request's SetBasicAuth. -func (r *Request) SetBasicAuth(username, password string) { - ((*http.Request)(r)).SetBasicAuth(username, password) -} - -// SetBody encodes the body in the request. -func (r *Request) SetBody(body interface{}) error { - switch b := body.(type) { - case string: - return r.setBodyString(b) - default: - return r.setBodyJson(body) - } -} - -// setBodyJson encodes the body as a struct to be marshaled via json.Marshal. -func (r *Request) setBodyJson(data interface{}) error { - body, err := json.Marshal(data) - if err != nil { - return err - } - r.Header.Set("Content-Type", "application/json") - r.setBodyReader(bytes.NewReader(body)) - return nil -} - -// setBodyString encodes the body as a string. -func (r *Request) setBodyString(body string) error { - return r.setBodyReader(strings.NewReader(body)) -} - -// setBodyReader writes the body from an io.Reader. -func (r *Request) setBodyReader(body io.Reader) error { - rc, ok := body.(io.ReadCloser) - if !ok && body != nil { - rc = ioutil.NopCloser(body) - } - r.Body = rc - if body != nil { - switch v := body.(type) { - case *strings.Reader: - r.ContentLength = int64(v.Len()) - case *bytes.Buffer: - r.ContentLength = int64(v.Len()) - } - } - return nil -} |