[MM-16768] Add support for Elasticsearch v7 (#12537)
* [MM-16768] Add support for Elasticsearch v7 * Fix i18n * Adds external services tracking to the telemetry * Rebuild elasticsearch interface mock * Rename diagnostics keys * Fix merge change
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3a8fb53f3e
Коммит
f7e93db512
185
vendor/github.com/olivere/elastic/CONTRIBUTORS
сгенерированный
поставляемый
Обычный файл
185
vendor/github.com/olivere/elastic/CONTRIBUTORS
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,185 @@
|
||||
# This is a list of people who have contributed code
|
||||
# to the Elastic repository.
|
||||
#
|
||||
# It is just my small "thank you" to all those that helped
|
||||
# making Elastic what it is.
|
||||
#
|
||||
# Please keep this list sorted.
|
||||
|
||||
0x6875790d0a [@huydx](https://github.com/huydx)
|
||||
Aaron Tami [@aarontami](https://github.com/aarontami)
|
||||
Adam Alix [@adamalix](https://github.com/adamalix)
|
||||
Adam Weiner [@adamweiner](https://github.com/adamweiner)
|
||||
Adrian Lungu [@AdrianLungu](https://github.com/AdrianLungu)
|
||||
alehano [@alehano](https://github.com/alehano)
|
||||
Alejandro Carstens [@alejandro-carstens](https://github.com/alejandro-carstens)
|
||||
Alex [@akotlar](https://github.com/akotlar)
|
||||
Alexander Sack [@asac](https://github.com/asac)
|
||||
Alexandre Olivier [@aliphen](https://github.com/aliphen)
|
||||
Alexey Sharov [@nizsheanez](https://github.com/nizsheanez)
|
||||
Anders [@ANerd](https://github.com/ANerd)
|
||||
AndreKR [@AndreKR](https://github.com/AndreKR)
|
||||
André Bierlein [@ligustah](https://github.com/ligustah)
|
||||
Andrew Dunham [@andrew-d](https://github.com/andrew-d)
|
||||
Andrew Gaul [@andrewgaul](https://github.com/andrewgaul)
|
||||
Andy Walker [@alaska](https://github.com/alaska)
|
||||
Arquivei [@arquivei](https://github.com/arquivei)
|
||||
Artemiy Elozhenko [@artezh](https://github.com/artezh)
|
||||
arthurgustin [@arthurgustin](https://github.com/arthurgustin)
|
||||
Bas van Dijk [@basvandijk](https://github.com/basvandijk)
|
||||
Benjamin Fernandes [@LotharSee](https://github.com/LotharSee)
|
||||
Benjamin Zarzycki [@kf6nux](https://github.com/kf6nux)
|
||||
Björn Gerdau [@kernle32dll](https://github.com/kernle32dll)
|
||||
Boris Popovschi [@Zyqsempai](https://github.com/Zyqsempai)
|
||||
Bowei Xu [@vancexu](https://github.com/vancexu)
|
||||
Braden Bassingthwaite [@bbassingthwaite-va](https://github.com/bbassingthwaite-va)
|
||||
Brady Love [@bradylove](https://github.com/bradylove)
|
||||
Bryan Conklin [@bmconklin](https://github.com/bmconklin)
|
||||
Bruce Zhou [@brucez-isell](https://github.com/brucez-isell)
|
||||
Carl Dunham [@carldunham](https://github.com/carldunham)
|
||||
Carl Johan Gustavsson [@cjgu](https://github.com/cjgu)
|
||||
Cat [@cat-turner](https://github.com/cat-turner)
|
||||
César Jiménez [@cesarjimenez](https://github.com/cesarjimenez)
|
||||
cforbes [@cforbes](https://github.com/cforbes)
|
||||
張泰瑋(Chang Tai Wei) [@david30907d](https://github.com/david30907d)
|
||||
Chris M [@tebriel](https://github.com/tebriel)
|
||||
Chris Rice [@donutmonger](https://github.com/donutmonger)
|
||||
Claudiu Olteanu [@claudiuolteanu](https://github.com/claudiuolteanu)
|
||||
Chris Duncan [@veqryn](https://github.com/veqryn)
|
||||
Chris Ludden [@cludden](https://github.com/cludden)
|
||||
Christophe Courtaut [@kri5](https://github.com/kri5)
|
||||
cmitchell [@cmitchell](https://github.com/cmitchell)
|
||||
Connor Peet [@connor4312](https://github.com/connor4312)
|
||||
Conrad Pankoff [@deoxxa](https://github.com/deoxxa)
|
||||
Corey Scott [@corsc](https://github.com/corsc)
|
||||
Chris Petersen [@ex-nerd](https://github.com/ex-nerd)
|
||||
Daniel Barrett [@shendaras](https://github.com/shendaras)
|
||||
Daniel Heckrath [@DanielHeckrath](https://github.com/DanielHeckrath)
|
||||
Daniel Imfeld [@dimfeld](https://github.com/dimfeld)
|
||||
Daniel Santos [@danlsgiga](https://github.com/danlsgiga)
|
||||
David Emanuel Buchmann [@wuurrd](https://github.com/wuurrd)
|
||||
Diego Becciolini [@itizir](https://github.com/itizir)
|
||||
Dwayne Schultz [@myshkin5](https://github.com/myshkin5)
|
||||
Elliot Williams [@elliotwms](https://github.com/elliotwms)
|
||||
Ellison Leão [@ellisonleao](https://github.com/ellisonleao)
|
||||
Erik Grinaker [@erikgrinaker](https://github.com/erikgrinaker)
|
||||
Erwin [@eticzon](https://github.com/eticzon)
|
||||
Etienne Lafarge [@elafarge](https://github.com/elafarge)
|
||||
Eugene Egorov [@EugeneEgorov](https://github.com/EugeneEgorov)
|
||||
Evan Shaw [@edsrzf](https://github.com/edsrzf)
|
||||
Fanfan [@wenpos](https://github.com/wenpos)
|
||||
Faolan C-P [@fcheslack](https://github.com/fcheslack)
|
||||
Filip Tepper [@filiptepper](https://github.com/filiptepper)
|
||||
Garrett Kelley [@GarrettKelley](https://github.com/GarrettKelley)
|
||||
Gaspard Douady [@plopik](https://github.com/plopik)
|
||||
Gaylord Aulke [@blafasel42](https://github.com/blafasel42)
|
||||
Gerhard Häring [@ghaering](https://github.com/ghaering)
|
||||
gregoryfranklin [@gregoryfranklin](https://github.com/gregoryfranklin)
|
||||
Guilherme Silveira [@guilherme-santos](https://github.com/guilherme-santos)
|
||||
Guillaume J. Charmes [@creack](https://github.com/creack)
|
||||
Guiseppe [@gm42](https://github.com/gm42)
|
||||
Han Yu [@MoonighT](https://github.com/MoonighT)
|
||||
Harmen [@alicebob](https://github.com/alicebob)
|
||||
Harrison Wright [@wright8191](https://github.com/wright8191)
|
||||
Henry Clifford [@hcliff](https://github.com/hcliff)
|
||||
Igor Dubinskiy [@idubinskiy](https://github.com/idubinskiy)
|
||||
initialcontext [@initialcontext](https://github.com/initialcontext)
|
||||
Isaac Saldana [@isaldana](https://github.com/isaldana)
|
||||
J Barkey Wolf [@jjhbw](https://github.com/jjhbw)
|
||||
Jack Lindamood [@cep21](https://github.com/cep21)
|
||||
Jacob [@jdelgad](https://github.com/jdelgad)
|
||||
Jan Düpmeier [@jduepmeier](https://github.com/jduepmeier)
|
||||
Jayme Rotsaert [@jrots](https://github.com/jrots)
|
||||
Jean-Alexandre Beaumont [@Enteris](https://github.com/Enteris)
|
||||
Jean-François Roche [@jfroche](https://github.com/jfroche)
|
||||
Jeff Rand [@jeffrand](https://github.com/jeffrand)
|
||||
Jeremy Canady [@jrmycanady](https://github.com/jrmycanady)
|
||||
Jérémie Vexiau [@texvex](https://github.com/texvex)
|
||||
Jesper Bränn [@Yopi](https://github.com/Yopi)
|
||||
Jim Berlage [@jimberlage](https://github.com/jimberlage)
|
||||
Joe Buck [@four2five](https://github.com/four2five)
|
||||
John Barker [@j16r](https://github.com/j16r)
|
||||
John Goodall [@jgoodall](https://github.com/jgoodall)
|
||||
John Stanford [@jxstanford](https://github.com/jxstanford)
|
||||
Jonas Groenaas Drange [@semafor](https://github.com/semafor)
|
||||
Josef Fröhle [@Dexus](https://github.com/Dexus)
|
||||
José Martínez [@xose](https://github.com/xose)
|
||||
Josh Chorlton [@jchorl](https://github.com/jchorl)
|
||||
Jpnock [@Jpnock](https://github.com/Jpnock)
|
||||
jun [@coseyo](https://github.com/coseyo)
|
||||
Junpei Tsuji [@jun06t](https://github.com/jun06t)
|
||||
kartlee [@kartlee](https://github.com/kartlee)
|
||||
Keith Hatton [@khatton-ft](https://github.com/khatton-ft)
|
||||
kel [@liketic](https://github.com/liketic)
|
||||
Kenta SUZUKI [@suzuken](https://github.com/suzuken)
|
||||
Kevin Mulvey [@kmulvey](https://github.com/kmulvey)
|
||||
Kyle Brandt [@kylebrandt](https://github.com/kylebrandt)
|
||||
Larry Cinnabar [@larrycinnabar](https://github.com/larrycinnabar)
|
||||
Leandro Piccilli [@lpic10](https://github.com/lpic10)
|
||||
Lee [@leezhm](https://github.com/leezhm)
|
||||
lechnertech [@lechnertech](https://github.com/lechnertech)
|
||||
M. Zulfa Achsani [@misterciput](https://github.com/misterciput)
|
||||
Maciej Lisiewski [@c2h5oh](https://github.com/c2h5oh)
|
||||
Mara Kim [@autochthe](https://github.com/autochthe)
|
||||
Marcy Buccellato [@marcybuccellato](https://github.com/marcybuccellato)
|
||||
Mark Costello [@mcos](https://github.com/mcos)
|
||||
Martin Häger [@protomouse](https://github.com/protomouse)
|
||||
Matt Braymer-Hayes [@mattayes](https://github.com/mattayes)
|
||||
Medhi Bechina [@mdzor](https://github.com/mdzor)
|
||||
Mike Beshai [@mbesh](https://github.com/mbesh)
|
||||
mmfrb [@mmfrb](https://github.com/mmfrb)
|
||||
mnpritula [@mnpritula](https://github.com/mnpritula)
|
||||
mosa [@mosasiru](https://github.com/mosasiru)
|
||||
Muhammet Çakır [@cakirmuha](https://github.com/cakirmuha)
|
||||
naimulhaider [@naimulhaider](https://github.com/naimulhaider)
|
||||
Naoya Yoshizawa [@azihsoyn](https://github.com/azihsoyn)
|
||||
navins [@ishare](https://github.com/ishare)
|
||||
Naoya Tsutsumi [@tutuming](https://github.com/tutuming)
|
||||
NeoCN [@NeoCN](https://github.com/NeoCN)
|
||||
Nicholas Wolff [@nwolff](https://github.com/nwolff)
|
||||
Nick K [@utrack](https://github.com/utrack)
|
||||
Nick Whyte [@nickw444](https://github.com/nickw444)
|
||||
Nicolae Vartolomei [@nvartolomei](https://github.com/nvartolomei)
|
||||
okhowang [@okhowang](https://github.com/okhowang)
|
||||
Orne Brocaar [@brocaar](https://github.com/brocaar)
|
||||
Paul [@eyeamera](https://github.com/eyeamera)
|
||||
Paul Oldenburg [@lr-paul](https://github.com/lr-paul)
|
||||
Pete C [@peteclark-ft](https://github.com/peteclark-ft)
|
||||
Peter Nagy [@nagypeterjob](https://github.com/nagypeterjob)
|
||||
Paolo [@ppiccolo](https://github.com/ppiccolo)
|
||||
Radoslaw Wesolowski [@r--w](https://github.com/r--w)
|
||||
Rafał Gałus [@rgalus](https://github.com/rgalus)
|
||||
rchicoli [@rchicoli](https://github.com/rchicoli)
|
||||
Roman Colohanin [@zuzmic](https://github.com/zuzmic)
|
||||
Ryan Schmukler [@rschmukler](https://github.com/rschmukler)
|
||||
Ryan Wynn [@rwynn](https://github.com/rwynn)
|
||||
Sacheendra talluri [@sacheendra](https://github.com/sacheendra)
|
||||
Sean DuBois [@Sean-Der](https://github.com/Sean-Der)
|
||||
Sagan Yaroslav [@sgnrslv](https://github.com/sgnrslv)
|
||||
Shalin LK [@shalinlk](https://github.com/shalinlk)
|
||||
singham [@zhaochenxiao90](https://github.com/zhaochenxiao90)
|
||||
Slawomir CALUCH [@slawo](https://github.com/slawo)
|
||||
soarpenguin [@soarpenguin](https://github.com/soarpenguin)
|
||||
Stephan Krynauw [@skrynauw](https://github.com/skrynauw)
|
||||
Stephen Kubovic [@stephenkubovic](https://github.com/stephenkubovic)
|
||||
Stuart Warren [@Woz](https://github.com/stuart-warren)
|
||||
Sulaiman [@salajlan](https://github.com/salajlan)
|
||||
Sundar [@sundarv85](https://github.com/sundarv85)
|
||||
Swarlston [@Swarlston](https://github.com/Swarlston)
|
||||
Take [ww24](https://github.com/ww24)
|
||||
Tetsuya Morimoto [@t2y](https://github.com/t2y)
|
||||
TheZeroSlave [@TheZeroSlave](https://github.com/TheZeroSlave)
|
||||
Tomasz Elendt [@telendt](https://github.com/telendt)
|
||||
TimeEmit [@TimeEmit](https://github.com/timeemit)
|
||||
TusharM [@tusharm](https://github.com/tusharm)
|
||||
wangtuo [@wangtuo](https://github.com/wangtuo)
|
||||
Wédney Yuri [@wedneyyuri](https://github.com/wedneyyuri)
|
||||
Wesley Kim [@wesleyk](https://github.com/wesleyk)
|
||||
wolfkdy [@wolfkdy](https://github.com/wolfkdy)
|
||||
Wyndham Blanton [@wyndhblb](https://github.com/wyndhblb)
|
||||
Yarden Bar [@ayashjorden](https://github.com/ayashjorden)
|
||||
Yuya Kusakabe [@higebu](https://github.com/higebu)
|
||||
zakthomas [@zakthomas](https://github.com/zakthomas)
|
||||
Zach [@snowzach](https://github.com/snowzach)
|
||||
zhangxin [@visaxin](https://github.com/visaxin)
|
||||
@林 [@zplzpl](https://github.com/zplzpl)
|
||||
20
vendor/github.com/olivere/elastic/LICENSE
сгенерированный
поставляемый
Обычный файл
20
vendor/github.com/olivere/elastic/LICENSE
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
Copyright © 2012-2015 Oliver Eilhard
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the “Software”), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
||||
87
vendor/github.com/olivere/elastic/config/config.go
сгенерированный
поставляемый
Обычный файл
87
vendor/github.com/olivere/elastic/config/config.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,87 @@
|
||||
// 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
|
||||
Healthcheck *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 := strings.TrimSuffix(strings.TrimPrefix(uri.Path, "/"), "/")
|
||||
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("healthcheck"); s != "" {
|
||||
if b, err := strconv.ParseBool(s); err == nil {
|
||||
cfg.Healthcheck = &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
|
||||
}
|
||||
9
vendor/github.com/olivere/elastic/config/doc.go
сгенерированный
поставляемый
Обычный файл
9
vendor/github.com/olivere/elastic/config/doc.go
сгенерированный
поставляемый
Обычный файл
@@ -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
|
||||
18
vendor/github.com/olivere/elastic/uritemplates/LICENSE
сгенерированный
поставляемый
Обычный файл
18
vendor/github.com/olivere/elastic/uritemplates/LICENSE
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,18 @@
|
||||
Copyright (c) 2013 Joshua Tacoma
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
359
vendor/github.com/olivere/elastic/uritemplates/uritemplates.go
сгенерированный
поставляемый
Обычный файл
359
vendor/github.com/olivere/elastic/uritemplates/uritemplates.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,359 @@
|
||||
// Copyright 2013 Joshua Tacoma. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package uritemplates is a level 4 implementation of RFC 6570 (URI
|
||||
// Template, http://tools.ietf.org/html/rfc6570).
|
||||
//
|
||||
// To use uritemplates, parse a template string and expand it with a value
|
||||
// map:
|
||||
//
|
||||
// template, _ := uritemplates.Parse("https://api.github.com/repos{/user,repo}")
|
||||
// values := make(map[string]interface{})
|
||||
// values["user"] = "jtacoma"
|
||||
// values["repo"] = "uritemplates"
|
||||
// expanded, _ := template.ExpandString(values)
|
||||
// fmt.Printf(expanded)
|
||||
//
|
||||
package uritemplates
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
unreserved = regexp.MustCompile("[^A-Za-z0-9\\-._~]")
|
||||
reserved = regexp.MustCompile("[^A-Za-z0-9\\-._~:/?#[\\]@!$&'()*+,;=]")
|
||||
validname = regexp.MustCompile("^([A-Za-z0-9_\\.]|%[0-9A-Fa-f][0-9A-Fa-f])+$")
|
||||
hex = []byte("0123456789ABCDEF")
|
||||
)
|
||||
|
||||
func pctEncode(src []byte) []byte {
|
||||
dst := make([]byte, len(src)*3)
|
||||
for i, b := range src {
|
||||
buf := dst[i*3 : i*3+3]
|
||||
buf[0] = 0x25
|
||||
buf[1] = hex[b/16]
|
||||
buf[2] = hex[b%16]
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
func escape(s string, allowReserved bool) (escaped string) {
|
||||
if allowReserved {
|
||||
escaped = string(reserved.ReplaceAllFunc([]byte(s), pctEncode))
|
||||
} else {
|
||||
escaped = string(unreserved.ReplaceAllFunc([]byte(s), pctEncode))
|
||||
}
|
||||
return escaped
|
||||
}
|
||||
|
||||
// A UriTemplate is a parsed representation of a URI template.
|
||||
type UriTemplate struct {
|
||||
raw string
|
||||
parts []templatePart
|
||||
}
|
||||
|
||||
// Parse parses a URI template string into a UriTemplate object.
|
||||
func Parse(rawtemplate string) (template *UriTemplate, err error) {
|
||||
template = new(UriTemplate)
|
||||
template.raw = rawtemplate
|
||||
split := strings.Split(rawtemplate, "{")
|
||||
template.parts = make([]templatePart, len(split)*2-1)
|
||||
for i, s := range split {
|
||||
if i == 0 {
|
||||
if strings.Contains(s, "}") {
|
||||
err = errors.New("unexpected }")
|
||||
break
|
||||
}
|
||||
template.parts[i].raw = s
|
||||
} else {
|
||||
subsplit := strings.Split(s, "}")
|
||||
if len(subsplit) != 2 {
|
||||
err = errors.New("malformed template")
|
||||
break
|
||||
}
|
||||
expression := subsplit[0]
|
||||
template.parts[i*2-1], err = parseExpression(expression)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
template.parts[i*2].raw = subsplit[1]
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
template = nil
|
||||
}
|
||||
return template, err
|
||||
}
|
||||
|
||||
type templatePart struct {
|
||||
raw string
|
||||
terms []templateTerm
|
||||
first string
|
||||
sep string
|
||||
named bool
|
||||
ifemp string
|
||||
allowReserved bool
|
||||
}
|
||||
|
||||
type templateTerm struct {
|
||||
name string
|
||||
explode bool
|
||||
truncate int
|
||||
}
|
||||
|
||||
func parseExpression(expression string) (result templatePart, err error) {
|
||||
switch expression[0] {
|
||||
case '+':
|
||||
result.sep = ","
|
||||
result.allowReserved = true
|
||||
expression = expression[1:]
|
||||
case '.':
|
||||
result.first = "."
|
||||
result.sep = "."
|
||||
expression = expression[1:]
|
||||
case '/':
|
||||
result.first = "/"
|
||||
result.sep = "/"
|
||||
expression = expression[1:]
|
||||
case ';':
|
||||
result.first = ";"
|
||||
result.sep = ";"
|
||||
result.named = true
|
||||
expression = expression[1:]
|
||||
case '?':
|
||||
result.first = "?"
|
||||
result.sep = "&"
|
||||
result.named = true
|
||||
result.ifemp = "="
|
||||
expression = expression[1:]
|
||||
case '&':
|
||||
result.first = "&"
|
||||
result.sep = "&"
|
||||
result.named = true
|
||||
result.ifemp = "="
|
||||
expression = expression[1:]
|
||||
case '#':
|
||||
result.first = "#"
|
||||
result.sep = ","
|
||||
result.allowReserved = true
|
||||
expression = expression[1:]
|
||||
default:
|
||||
result.sep = ","
|
||||
}
|
||||
rawterms := strings.Split(expression, ",")
|
||||
result.terms = make([]templateTerm, len(rawterms))
|
||||
for i, raw := range rawterms {
|
||||
result.terms[i], err = parseTerm(raw)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func parseTerm(term string) (result templateTerm, err error) {
|
||||
if strings.HasSuffix(term, "*") {
|
||||
result.explode = true
|
||||
term = term[:len(term)-1]
|
||||
}
|
||||
split := strings.Split(term, ":")
|
||||
if len(split) == 1 {
|
||||
result.name = term
|
||||
} else if len(split) == 2 {
|
||||
result.name = split[0]
|
||||
var parsed int64
|
||||
parsed, err = strconv.ParseInt(split[1], 10, 0)
|
||||
result.truncate = int(parsed)
|
||||
} else {
|
||||
err = errors.New("multiple colons in same term")
|
||||
}
|
||||
if !validname.MatchString(result.name) {
|
||||
err = errors.New("not a valid name: " + result.name)
|
||||
}
|
||||
if result.explode && result.truncate > 0 {
|
||||
err = errors.New("both explode and prefix modifers on same term")
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Expand expands a URI template with a set of values to produce a string.
|
||||
func (self *UriTemplate) Expand(value interface{}) (string, error) {
|
||||
values, ismap := value.(map[string]interface{})
|
||||
if !ismap {
|
||||
if m, ismap := struct2map(value); !ismap {
|
||||
return "", errors.New("expected map[string]interface{}, struct, or pointer to struct.")
|
||||
} else {
|
||||
return self.Expand(m)
|
||||
}
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
for _, p := range self.parts {
|
||||
err := p.expand(&buf, values)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
||||
func (self *templatePart) expand(buf *bytes.Buffer, values map[string]interface{}) error {
|
||||
if len(self.raw) > 0 {
|
||||
buf.WriteString(self.raw)
|
||||
return nil
|
||||
}
|
||||
var zeroLen = buf.Len()
|
||||
buf.WriteString(self.first)
|
||||
var firstLen = buf.Len()
|
||||
for _, term := range self.terms {
|
||||
value, exists := values[term.name]
|
||||
if !exists {
|
||||
continue
|
||||
}
|
||||
if buf.Len() != firstLen {
|
||||
buf.WriteString(self.sep)
|
||||
}
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
self.expandString(buf, term, v)
|
||||
case []interface{}:
|
||||
self.expandArray(buf, term, v)
|
||||
case map[string]interface{}:
|
||||
if term.truncate > 0 {
|
||||
return errors.New("cannot truncate a map expansion")
|
||||
}
|
||||
self.expandMap(buf, term, v)
|
||||
default:
|
||||
if m, ismap := struct2map(value); ismap {
|
||||
if term.truncate > 0 {
|
||||
return errors.New("cannot truncate a map expansion")
|
||||
}
|
||||
self.expandMap(buf, term, m)
|
||||
} else {
|
||||
str := fmt.Sprintf("%v", value)
|
||||
self.expandString(buf, term, str)
|
||||
}
|
||||
}
|
||||
}
|
||||
if buf.Len() == firstLen {
|
||||
original := buf.Bytes()[:zeroLen]
|
||||
buf.Reset()
|
||||
buf.Write(original)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *templatePart) expandName(buf *bytes.Buffer, name string, empty bool) {
|
||||
if self.named {
|
||||
buf.WriteString(name)
|
||||
if empty {
|
||||
buf.WriteString(self.ifemp)
|
||||
} else {
|
||||
buf.WriteString("=")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *templatePart) expandString(buf *bytes.Buffer, t templateTerm, s string) {
|
||||
if len(s) > t.truncate && t.truncate > 0 {
|
||||
s = s[:t.truncate]
|
||||
}
|
||||
self.expandName(buf, t.name, len(s) == 0)
|
||||
buf.WriteString(escape(s, self.allowReserved))
|
||||
}
|
||||
|
||||
func (self *templatePart) expandArray(buf *bytes.Buffer, t templateTerm, a []interface{}) {
|
||||
if len(a) == 0 {
|
||||
return
|
||||
} else if !t.explode {
|
||||
self.expandName(buf, t.name, false)
|
||||
}
|
||||
for i, value := range a {
|
||||
if t.explode && i > 0 {
|
||||
buf.WriteString(self.sep)
|
||||
} else if i > 0 {
|
||||
buf.WriteString(",")
|
||||
}
|
||||
var s string
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
s = v
|
||||
default:
|
||||
s = fmt.Sprintf("%v", v)
|
||||
}
|
||||
if len(s) > t.truncate && t.truncate > 0 {
|
||||
s = s[:t.truncate]
|
||||
}
|
||||
if self.named && t.explode {
|
||||
self.expandName(buf, t.name, len(s) == 0)
|
||||
}
|
||||
buf.WriteString(escape(s, self.allowReserved))
|
||||
}
|
||||
}
|
||||
|
||||
func (self *templatePart) expandMap(buf *bytes.Buffer, t templateTerm, m map[string]interface{}) {
|
||||
if len(m) == 0 {
|
||||
return
|
||||
}
|
||||
if !t.explode {
|
||||
self.expandName(buf, t.name, len(m) == 0)
|
||||
}
|
||||
var firstLen = buf.Len()
|
||||
for k, value := range m {
|
||||
if firstLen != buf.Len() {
|
||||
if t.explode {
|
||||
buf.WriteString(self.sep)
|
||||
} else {
|
||||
buf.WriteString(",")
|
||||
}
|
||||
}
|
||||
var s string
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
s = v
|
||||
default:
|
||||
s = fmt.Sprintf("%v", v)
|
||||
}
|
||||
if t.explode {
|
||||
buf.WriteString(escape(k, self.allowReserved))
|
||||
buf.WriteRune('=')
|
||||
buf.WriteString(escape(s, self.allowReserved))
|
||||
} else {
|
||||
buf.WriteString(escape(k, self.allowReserved))
|
||||
buf.WriteRune(',')
|
||||
buf.WriteString(escape(s, self.allowReserved))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func struct2map(v interface{}) (map[string]interface{}, bool) {
|
||||
value := reflect.ValueOf(v)
|
||||
switch value.Type().Kind() {
|
||||
case reflect.Ptr:
|
||||
return struct2map(value.Elem().Interface())
|
||||
case reflect.Struct:
|
||||
m := make(map[string]interface{})
|
||||
for i := 0; i < value.NumField(); i++ {
|
||||
tag := value.Type().Field(i).Tag
|
||||
var name string
|
||||
if strings.Contains(string(tag), ":") {
|
||||
name = tag.Get("uri")
|
||||
} else {
|
||||
name = strings.TrimSpace(string(tag))
|
||||
}
|
||||
if len(name) == 0 {
|
||||
name = value.Type().Field(i).Name
|
||||
}
|
||||
m[name] = value.Field(i).Interface()
|
||||
}
|
||||
return m, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
13
vendor/github.com/olivere/elastic/uritemplates/utils.go
сгенерированный
поставляемый
Обычный файл
13
vendor/github.com/olivere/elastic/uritemplates/utils.go
сгенерированный
поставляемый
Обычный файл
@@ -0,0 +1,13 @@
|
||||
package uritemplates
|
||||
|
||||
func Expand(path string, expansions map[string]string) (string, error) {
|
||||
template, err := Parse(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
values := make(map[string]interface{})
|
||||
for k, v := range expansions {
|
||||
values[k] = v
|
||||
}
|
||||
return template.Expand(values)
|
||||
}
|
||||
Ссылка в новой задаче
Block a user