Initial commit

This commit is contained in:
Donny
2019-04-22 20:46:32 +08:00
commit 49ab8aadd1
25441 changed files with 4055000 additions and 0 deletions

32
vendor/gopkg.in/olivere/elastic.v5/config/BUILD.bazel generated vendored Normal file
View File

@@ -0,0 +1,32 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"config.go",
"doc.go",
],
importmap = "go-common/vendor/gopkg.in/olivere/elastic.v5/config",
importpath = "gopkg.in/olivere/elastic.v5/config",
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = ["config_test.go"],
embed = [":go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

90
vendor/gopkg.in/olivere/elastic.v5/config/config.go generated vendored Normal file
View File

@@ -0,0 +1,90 @@
// 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 config
import (
"fmt"
"net/url"
"strconv"
"strings"
)
// Config represents an Elasticsearch configuration.
type Config struct {
URL string
Index string
Username string
Password string
Shards int
Replicas int
Sniff *bool
Infolog string
Errorlog string
Tracelog string
}
// Parse returns the Elasticsearch configuration by extracting it
// from the URL, its path, and its query string.
//
// Example:
// http://127.0.0.1:9200/store-blobs?shards=1&replicas=0&sniff=false&tracelog=elastic.trace.log
//
// The code above will return a URL of http://127.0.0.1:9200, an index name
// of store-blobs, and the related settings from the query string.
func Parse(elasticURL string) (*Config, error) {
cfg := &Config{
Shards: 1,
Replicas: 0,
Sniff: nil,
}
uri, err := url.Parse(elasticURL)
if err != nil {
return nil, fmt.Errorf("error parsing elastic parameter %q: %v", elasticURL, err)
}
index := uri.Path
if strings.HasPrefix(index, "/") {
index = index[1:]
}
if strings.HasSuffix(index, "/") {
index = index[:len(index)-1]
}
if index == "" {
return nil, fmt.Errorf("missing index in elastic parameter %q", elasticURL)
}
if uri.User != nil {
cfg.Username = uri.User.Username()
cfg.Password, _ = uri.User.Password()
}
uri.User = nil
if i, err := strconv.Atoi(uri.Query().Get("shards")); err == nil {
cfg.Shards = i
}
if i, err := strconv.Atoi(uri.Query().Get("replicas")); err == nil {
cfg.Replicas = i
}
if s := uri.Query().Get("sniff"); s != "" {
if b, err := strconv.ParseBool(s); err == nil {
cfg.Sniff = &b
}
}
if s := uri.Query().Get("infolog"); s != "" {
cfg.Infolog = s
}
if s := uri.Query().Get("errorlog"); s != "" {
cfg.Errorlog = s
}
if s := uri.Query().Get("tracelog"); s != "" {
cfg.Tracelog = s
}
uri.Path = ""
uri.RawQuery = ""
cfg.URL = uri.String()
cfg.Index = index
return cfg, nil
}

View File

@@ -0,0 +1,45 @@
// 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 config
import "testing"
func TestParse(t *testing.T) {
urls := "http://user:pwd@elastic:19220/store-blobs?shards=5&replicas=2&sniff=true&errorlog=elastic.error.log&infolog=elastic.info.log&tracelog=elastic.trace.log"
cfg, err := Parse(urls)
if err != nil {
t.Fatal(err)
}
if want, got := "http://elastic:19220", cfg.URL; want != got {
t.Fatalf("expected URL = %q, got %q", want, got)
}
if want, got := "store-blobs", cfg.Index; want != got {
t.Fatalf("expected Index = %q, got %q", want, got)
}
if want, got := "user", cfg.Username; want != got {
t.Fatalf("expected Username = %q, got %q", want, got)
}
if want, got := "pwd", cfg.Password; want != got {
t.Fatalf("expected Password = %q, got %q", want, got)
}
if want, got := 5, cfg.Shards; want != got {
t.Fatalf("expected Shards = %v, got %v", want, got)
}
if want, got := 2, cfg.Replicas; want != got {
t.Fatalf("expected Replicas = %v, got %v", want, got)
}
if want, got := true, *cfg.Sniff; want != got {
t.Fatalf("expected Sniff = %v, got %v", want, got)
}
if want, got := "elastic.error.log", cfg.Errorlog; want != got {
t.Fatalf("expected Errorlog = %q, got %q", want, got)
}
if want, got := "elastic.info.log", cfg.Infolog; want != got {
t.Fatalf("expected Infolog = %q, got %q", want, got)
}
if want, got := "elastic.trace.log", cfg.Tracelog; want != got {
t.Fatalf("expected Tracelog = %q, got %q", want, got)
}
}

9
vendor/gopkg.in/olivere/elastic.v5/config/doc.go generated vendored Normal file
View File

@@ -0,0 +1,9 @@
// 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 config allows parsing a configuration for Elasticsearch
from a URL.
*/
package config