mirror of
https://github.com/pgsty/minio.git
synced 2026-08-09 15:53:28 +03:00
a2a8d54bb6
This change adds `access` format support for notifications to a Elasticsearch server, and it refactors `namespace` format support. In the case of `access` format, for each event in Minio, a JSON document is inserted into Elasticsearch with its timestamp set to the event's timestamp, and with the ID generated automatically by elasticsearch. No events are modified or deleted in this mode. In the case of `namespace` format, for each event in Minio, a JSON document is keyed together by the bucket and object name is updated in Elasticsearch. In the case of an object being created or over-written in Minio, a new document or an existing document is inserted into the Elasticsearch index. If an object is deleted in Minio, the corresponding document is deleted from the Elasticsearch index. Additionally, this change upgrades Elasticsearch support to the 5.x series. This is a breaking change, and users of previous elasticsearch versions should upgrade. Also updates documentation on Elasticsearch notification target usage and has a link to an elasticsearch upgrade guide. This is the last patch that finally resolves #3928.
75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
// Copyright 2016 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// +build go1.7
|
|
|
|
// Package ctxhttp provides helper functions for performing context-aware HTTP requests.
|
|
package ctxhttp // import "golang.org/x/net/context/ctxhttp"
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
// Do sends an HTTP request with the provided http.Client and returns
|
|
// an HTTP response.
|
|
//
|
|
// If the client is nil, http.DefaultClient is used.
|
|
//
|
|
// The provided ctx must be non-nil. If it is canceled or times out,
|
|
// ctx.Err() will be returned.
|
|
func Do(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error) {
|
|
if client == nil {
|
|
client = http.DefaultClient
|
|
}
|
|
resp, err := client.Do(req.WithContext(ctx))
|
|
// If we got an error, and the context has been canceled,
|
|
// the context's error is probably more useful.
|
|
if err != nil {
|
|
select {
|
|
case <-ctx.Done():
|
|
err = ctx.Err()
|
|
default:
|
|
}
|
|
}
|
|
return resp, err
|
|
}
|
|
|
|
// Get issues a GET request via the Do function.
|
|
func Get(ctx context.Context, client *http.Client, url string) (*http.Response, error) {
|
|
req, err := http.NewRequest("GET", url, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return Do(ctx, client, req)
|
|
}
|
|
|
|
// Head issues a HEAD request via the Do function.
|
|
func Head(ctx context.Context, client *http.Client, url string) (*http.Response, error) {
|
|
req, err := http.NewRequest("HEAD", url, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return Do(ctx, client, req)
|
|
}
|
|
|
|
// Post issues a POST request via the Do function.
|
|
func Post(ctx context.Context, client *http.Client, url string, bodyType string, body io.Reader) (*http.Response, error) {
|
|
req, err := http.NewRequest("POST", url, body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req.Header.Set("Content-Type", bodyType)
|
|
return Do(ctx, client, req)
|
|
}
|
|
|
|
// PostForm issues a POST request via the Do function.
|
|
func PostForm(ctx context.Context, client *http.Client, url string, data url.Values) (*http.Response, error) {
|
|
return Post(ctx, client, url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
|
|
}
|