diff --git a/_third_party/github.com/StackExchange/wmi/wmi.go b/_third_party/github.com/StackExchange/wmi/wmi.go index 2f2e6d11fd..334e31f346 100644 --- a/_third_party/github.com/StackExchange/wmi/wmi.go +++ b/_third_party/github.com/StackExchange/wmi/wmi.go @@ -289,20 +289,21 @@ func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismat } } case string: - iv, err := strconv.ParseInt(val, 10, 64) switch f.Kind() { case reflect.String: f.SetString(val) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + iv, err := strconv.ParseInt(val, 10, 64) if err != nil { return err } f.SetInt(iv) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + uv, err := strconv.ParseUint(val, 10, 64) if err != nil { return err } - f.SetUint(uint64(iv)) + f.SetUint(uv) case reflect.Struct: switch f.Type() { case timeType: diff --git a/_third_party/github.com/gorilla/mux/mux_test.go b/_third_party/github.com/gorilla/mux/mux_test.go index c841c4f1d7..b9646f8864 100644 --- a/_third_party/github.com/gorilla/mux/mux_test.go +++ b/_third_party/github.com/gorilla/mux/mux_test.go @@ -135,6 +135,33 @@ func TestHost(t *testing.T) { path: "", shouldMatch: false, }, + { + title: "Path route with single pattern with pipe, match", + route: new(Route).Path("/{category:a|b/c}"), + request: newRequest("GET", "http://localhost/a"), + vars: map[string]string{"category": "a"}, + host: "", + path: "/a", + shouldMatch: true, + }, + { + title: "Path route with single pattern with pipe, match", + route: new(Route).Path("/{category:a|b/c}"), + request: newRequest("GET", "http://localhost/b/c"), + vars: map[string]string{"category": "b/c"}, + host: "", + path: "/b/c", + shouldMatch: true, + }, + { + title: "Path route with multiple patterns with pipe, match", + route: new(Route).Path("/{category:a|b/c}/{product}/{id:[0-9]+}"), + request: newRequest("GET", "http://localhost/a/product_name/1"), + vars: map[string]string{"category": "a", "product": "product_name", "id": "1"}, + host: "", + path: "/a/product_name/1", + shouldMatch: true, + }, } for _, test := range tests { testRoute(t, test) diff --git a/_third_party/github.com/olivere/elastic/README.md b/_third_party/github.com/olivere/elastic/README.md index 7dd04b0505..c741b65a34 100644 --- a/_third_party/github.com/olivere/elastic/README.md +++ b/_third_party/github.com/olivere/elastic/README.md @@ -278,7 +278,7 @@ on the command line. - [x] `bool` - [x] `exists` - [ ] `geo_bounding_box` -- [ ] `geo_distance` +- [x] `geo_distance` - [ ] `geo_distance_range` - [x] `geo_polygon` - [ ] `geoshape` diff --git a/_third_party/github.com/olivere/elastic/search_aggs_avg.go b/_third_party/github.com/olivere/elastic/search_aggs_avg.go index 6232e13504..7b01ee0092 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_avg.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_avg.go @@ -13,6 +13,7 @@ package elastic type AvgAggregation struct { field string script string + scriptFile string lang string format string params map[string]interface{} @@ -37,6 +38,11 @@ func (a AvgAggregation) Script(script string) AvgAggregation { return a } +func (a AvgAggregation) ScriptFile(scriptFile string) AvgAggregation { + a.scriptFile = scriptFile + return a +} + func (a AvgAggregation) Lang(lang string) AvgAggregation { a.lang = lang return a @@ -77,6 +83,9 @@ func (a AvgAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_cardinality.go b/_third_party/github.com/olivere/elastic/search_aggs_cardinality.go index 562580d659..5d641346ca 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_cardinality.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_cardinality.go @@ -12,6 +12,7 @@ package elastic type CardinalityAggregation struct { field string script string + scriptFile string lang string format string params map[string]interface{} @@ -38,6 +39,11 @@ func (a CardinalityAggregation) Script(script string) CardinalityAggregation { return a } +func (a CardinalityAggregation) ScriptFile(scriptFile string) CardinalityAggregation { + a.scriptFile = scriptFile + return a +} + func (a CardinalityAggregation) Lang(lang string) CardinalityAggregation { a.lang = lang return a @@ -90,6 +96,9 @@ func (a CardinalityAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_date_histogram.go b/_third_party/github.com/olivere/elastic/search_aggs_date_histogram.go index 645b2560f9..9b593bd51a 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_date_histogram.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_date_histogram.go @@ -10,6 +10,7 @@ package elastic type DateHistogramAggregation struct { field string script string + scriptFile string lang string params map[string]interface{} subAggregations map[string]Aggregation @@ -47,6 +48,11 @@ func (a DateHistogramAggregation) Script(script string) DateHistogramAggregation return a } +func (a DateHistogramAggregation) ScriptFile(scriptFile string) DateHistogramAggregation { + a.scriptFile = scriptFile + return a +} + func (a DateHistogramAggregation) Lang(lang string) DateHistogramAggregation { a.lang = lang return a @@ -229,6 +235,9 @@ func (a DateHistogramAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_date_range.go b/_third_party/github.com/olivere/elastic/search_aggs_date_range.go index ffb841b09c..c0c550e8e0 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_date_range.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_date_range.go @@ -19,6 +19,7 @@ import ( type DateRangeAggregation struct { field string script string + scriptFile string lang string params map[string]interface{} subAggregations map[string]Aggregation @@ -53,6 +54,11 @@ func (a DateRangeAggregation) Script(script string) DateRangeAggregation { return a } +func (a DateRangeAggregation) ScriptFile(scriptFile string) DateRangeAggregation { + a.scriptFile = scriptFile + return a +} + func (a DateRangeAggregation) Lang(lang string) DateRangeAggregation { a.lang = lang return a @@ -174,6 +180,9 @@ func (a DateRangeAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_extended_stats.go b/_third_party/github.com/olivere/elastic/search_aggs_extended_stats.go index 29db2f6192..76cd572ce4 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_extended_stats.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_extended_stats.go @@ -12,6 +12,7 @@ package elastic type ExtendedStatsAggregation struct { field string script string + scriptFile string lang string format string params map[string]interface{} @@ -36,6 +37,11 @@ func (a ExtendedStatsAggregation) Script(script string) ExtendedStatsAggregation return a } +func (a ExtendedStatsAggregation) ScriptFile(scriptFile string) ExtendedStatsAggregation { + a.scriptFile = scriptFile + return a +} + func (a ExtendedStatsAggregation) Lang(lang string) ExtendedStatsAggregation { a.lang = lang return a @@ -76,6 +82,9 @@ func (a ExtendedStatsAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_geo_bounds.go b/_third_party/github.com/olivere/elastic/search_aggs_geo_bounds.go index bd928d1db3..33d9eb9ab5 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_geo_bounds.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_geo_bounds.go @@ -10,6 +10,7 @@ package elastic type GeoBoundsAggregation struct { field string script string + scriptFile string lang string params map[string]interface{} wrapLongitude *bool @@ -30,6 +31,11 @@ func (a GeoBoundsAggregation) Script(script string) GeoBoundsAggregation { return a } +func (a GeoBoundsAggregation) ScriptFile(scriptFile string) GeoBoundsAggregation { + a.scriptFile = scriptFile + return a +} + func (a GeoBoundsAggregation) Lang(lang string) GeoBoundsAggregation { a.lang = lang return a @@ -81,6 +87,9 @@ func (a GeoBoundsAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_histogram.go b/_third_party/github.com/olivere/elastic/search_aggs_histogram.go index 0ac44ef90c..250d3f7fc1 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_histogram.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_histogram.go @@ -12,6 +12,7 @@ package elastic type HistogramAggregation struct { field string script string + scriptFile string lang string params map[string]interface{} subAggregations map[string]Aggregation @@ -42,6 +43,11 @@ func (a HistogramAggregation) Script(script string) HistogramAggregation { return a } +func (a HistogramAggregation) ScriptFile(scriptFile string) HistogramAggregation { + a.scriptFile = scriptFile + return a +} + func (a HistogramAggregation) Lang(lang string) HistogramAggregation { a.lang = lang return a diff --git a/_third_party/github.com/olivere/elastic/search_aggs_max.go b/_third_party/github.com/olivere/elastic/search_aggs_max.go index 2d390b860b..9e77ef7a1a 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_max.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_max.go @@ -13,6 +13,7 @@ package elastic type MaxAggregation struct { field string script string + scriptFile string lang string format string params map[string]interface{} @@ -37,6 +38,11 @@ func (a MaxAggregation) Script(script string) MaxAggregation { return a } +func (a MaxAggregation) ScriptFile(scriptFile string) MaxAggregation { + a.scriptFile = scriptFile + return a +} + func (a MaxAggregation) Lang(lang string) MaxAggregation { a.lang = lang return a @@ -77,6 +83,9 @@ func (a MaxAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_min.go b/_third_party/github.com/olivere/elastic/search_aggs_min.go index a299e06b18..9e00bd3002 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_min.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_min.go @@ -13,6 +13,7 @@ package elastic type MinAggregation struct { field string script string + scriptFile string lang string format string params map[string]interface{} @@ -37,6 +38,11 @@ func (a MinAggregation) Script(script string) MinAggregation { return a } +func (a MinAggregation) ScriptFile(scriptFile string) MinAggregation { + a.scriptFile = scriptFile + return a +} + func (a MinAggregation) Lang(lang string) MinAggregation { a.lang = lang return a @@ -77,6 +83,9 @@ func (a MinAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_percentile_ranks.go b/_third_party/github.com/olivere/elastic/search_aggs_percentile_ranks.go index 7fa0bb8823..7e058d502a 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_percentile_ranks.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_percentile_ranks.go @@ -9,6 +9,7 @@ package elastic type PercentileRanksAggregation struct { field string script string + scriptFile string lang string format string params map[string]interface{} @@ -37,6 +38,11 @@ func (a PercentileRanksAggregation) Script(script string) PercentileRanksAggrega return a } +func (a PercentileRanksAggregation) ScriptFile(scriptFile string) PercentileRanksAggregation { + a.scriptFile = scriptFile + return a +} + func (a PercentileRanksAggregation) Lang(lang string) PercentileRanksAggregation { a.lang = lang return a @@ -100,6 +106,9 @@ func (a PercentileRanksAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_percentiles.go b/_third_party/github.com/olivere/elastic/search_aggs_percentiles.go index 166d2c6778..5b6cff92da 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_percentiles.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_percentiles.go @@ -9,6 +9,7 @@ package elastic type PercentilesAggregation struct { field string script string + scriptFile string lang string format string params map[string]interface{} @@ -37,6 +38,11 @@ func (a PercentilesAggregation) Script(script string) PercentilesAggregation { return a } +func (a PercentilesAggregation) ScriptFile(scriptFile string) PercentilesAggregation { + a.scriptFile = scriptFile + return a +} + func (a PercentilesAggregation) Lang(lang string) PercentilesAggregation { a.lang = lang return a @@ -99,6 +105,9 @@ func (a PercentilesAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_range.go b/_third_party/github.com/olivere/elastic/search_aggs_range.go index cb07ae825a..5b05423acf 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_range.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_range.go @@ -18,6 +18,7 @@ import ( type RangeAggregation struct { field string script string + scriptFile string lang string params map[string]interface{} subAggregations map[string]Aggregation @@ -51,6 +52,11 @@ func (a RangeAggregation) Script(script string) RangeAggregation { return a } +func (a RangeAggregation) ScriptFile(scriptFile string) RangeAggregation { + a.scriptFile = scriptFile + return a +} + func (a RangeAggregation) Lang(lang string) RangeAggregation { a.lang = lang return a @@ -166,6 +172,9 @@ func (a RangeAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_stats.go b/_third_party/github.com/olivere/elastic/search_aggs_stats.go index 1550d852aa..2bc6b274a2 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_stats.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_stats.go @@ -12,6 +12,7 @@ package elastic type StatsAggregation struct { field string script string + scriptFile string lang string format string params map[string]interface{} @@ -36,6 +37,11 @@ func (a StatsAggregation) Script(script string) StatsAggregation { return a } +func (a StatsAggregation) ScriptFile(scriptFile string) StatsAggregation { + a.scriptFile = scriptFile + return a +} + func (a StatsAggregation) Lang(lang string) StatsAggregation { a.lang = lang return a @@ -76,6 +82,9 @@ func (a StatsAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_sum.go b/_third_party/github.com/olivere/elastic/search_aggs_sum.go index c1865ce886..2aaee60227 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_sum.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_sum.go @@ -12,6 +12,7 @@ package elastic type SumAggregation struct { field string script string + scriptFile string lang string format string params map[string]interface{} @@ -36,6 +37,11 @@ func (a SumAggregation) Script(script string) SumAggregation { return a } +func (a SumAggregation) ScriptFile(scriptFile string) SumAggregation { + a.scriptFile = scriptFile + return a +} + func (a SumAggregation) Lang(lang string) SumAggregation { a.lang = lang return a @@ -76,6 +82,9 @@ func (a SumAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_terms.go b/_third_party/github.com/olivere/elastic/search_aggs_terms.go index 1b3787060f..d38c0663d7 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_terms.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_terms.go @@ -10,6 +10,7 @@ package elastic type TermsAggregation struct { field string script string + scriptFile string lang string params map[string]interface{} subAggregations map[string]Aggregation @@ -53,6 +54,11 @@ func (a TermsAggregation) Script(script string) TermsAggregation { return a } +func (a TermsAggregation) ScriptFile(scriptFile string) TermsAggregation { + a.scriptFile = scriptFile + return a +} + func (a TermsAggregation) Lang(lang string) TermsAggregation { a.lang = lang return a @@ -247,6 +253,9 @@ func (a TermsAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_aggs_value_count.go b/_third_party/github.com/olivere/elastic/search_aggs_value_count.go index 1ffe2a4b53..b38d783872 100644 --- a/_third_party/github.com/olivere/elastic/search_aggs_value_count.go +++ b/_third_party/github.com/olivere/elastic/search_aggs_value_count.go @@ -15,6 +15,7 @@ package elastic type ValueCountAggregation struct { field string script string + scriptFile string lang string format string params map[string]interface{} @@ -39,6 +40,11 @@ func (a ValueCountAggregation) Script(script string) ValueCountAggregation { return a } +func (a ValueCountAggregation) ScriptFile(scriptFile string) ValueCountAggregation { + a.scriptFile = scriptFile + return a +} + func (a ValueCountAggregation) Lang(lang string) ValueCountAggregation { a.lang = lang return a @@ -79,6 +85,9 @@ func (a ValueCountAggregation) Source() interface{} { if a.script != "" { opts["script"] = a.script } + if a.scriptFile != "" { + opts["script_file"] = a.scriptFile + } if a.lang != "" { opts["lang"] = a.lang } diff --git a/_third_party/github.com/olivere/elastic/search_filters_geo_distance.go b/_third_party/github.com/olivere/elastic/search_filters_geo_distance.go new file mode 100644 index 0000000000..17f88124cb --- /dev/null +++ b/_third_party/github.com/olivere/elastic/search_filters_geo_distance.go @@ -0,0 +1,136 @@ +// Copyright 2012-2015 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 + +// GeoDistanceFilter filters documents that include only hits that exists +// within a specific distance from a geo point. +// +// For more details, see: +// http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-filter.html +type GeoDistanceFilter struct { + Filter + name string + distance string + lat float64 + lon float64 + geohash string + distanceType string + optimizeBbox string + cache *bool + cacheKey string + filterName string +} + +// NewGeoDistanceFilter creates a new GeoDistanceFilter. +func NewGeoDistanceFilter(name string) GeoDistanceFilter { + f := GeoDistanceFilter{name: name} + return f +} + +func (f GeoDistanceFilter) Distance(distance string) GeoDistanceFilter { + f.distance = distance + return f +} + +func (f GeoDistanceFilter) GeoPoint(point *GeoPoint) GeoDistanceFilter { + f.lat = point.Lat + f.lon = point.Lon + return f +} + +func (f GeoDistanceFilter) Point(lat, lon float64) GeoDistanceFilter { + f.lat = lat + f.lon = lon + return f +} + +func (f GeoDistanceFilter) Lat(lat float64) GeoDistanceFilter { + f.lat = lat + return f +} + +func (f GeoDistanceFilter) Lon(lon float64) GeoDistanceFilter { + f.lon = lon + return f +} + +func (f GeoDistanceFilter) GeoHash(geohash string) GeoDistanceFilter { + f.geohash = geohash + return f +} + +func (f GeoDistanceFilter) DistanceType(distanceType string) GeoDistanceFilter { + f.distanceType = distanceType + return f +} + +func (f GeoDistanceFilter) OptimizeBbox(optimizeBbox string) GeoDistanceFilter { + f.optimizeBbox = optimizeBbox + return f +} + +func (f GeoDistanceFilter) Cache(cache bool) GeoDistanceFilter { + f.cache = &cache + return f +} + +func (f GeoDistanceFilter) CacheKey(cacheKey string) GeoDistanceFilter { + f.cacheKey = cacheKey + return f +} + +func (f GeoDistanceFilter) FilterName(filterName string) GeoDistanceFilter { + f.filterName = filterName + return f +} + +// Creates the query source for the geo_distance filter. +func (f GeoDistanceFilter) Source() interface{} { + // { + // "geo_distance" : { + // "distance" : "200km", + // "pin.location" : { + // "lat" : 40, + // "lon" : -70 + // } + // } + // } + + source := make(map[string]interface{}) + + params := make(map[string]interface{}) + + if f.geohash != "" { + params[f.name] = f.geohash + } else { + location := make(map[string]interface{}) + location["lat"] = f.lat + location["lon"] = f.lon + params[f.name] = location + } + + if f.distance != "" { + params["distance"] = f.distance + } + if f.distanceType != "" { + params["distance_type"] = f.distanceType + } + if f.optimizeBbox != "" { + params["optimize_bbox"] = f.optimizeBbox + } + if f.cache != nil { + params["_cache"] = *f.cache + } + if f.cacheKey != "" { + params["_cache_key"] = f.cacheKey + } + if f.filterName != "" { + params["_name"] = f.filterName + } + + source["geo_distance"] = params + + return source +} diff --git a/_third_party/github.com/olivere/elastic/search_filters_geo_distance_test.go b/_third_party/github.com/olivere/elastic/search_filters_geo_distance_test.go new file mode 100644 index 0000000000..3eca10960a --- /dev/null +++ b/_third_party/github.com/olivere/elastic/search_filters_geo_distance_test.go @@ -0,0 +1,58 @@ +// Copyright 2012-2015 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 ( + "encoding/json" + "testing" +) + +func TestGeoDistanceFilter(t *testing.T) { + f := NewGeoDistanceFilter("pin.location") + f = f.Lat(40) + f = f.Lon(-70) + f = f.Distance("200km") + f = f.DistanceType("plane") + f = f.OptimizeBbox("memory") + data, err := json.Marshal(f.Source()) + if err != nil { + t.Fatalf("marshaling to JSON failed: %v", err) + } + got := string(data) + expected := `{"geo_distance":{"distance":"200km","distance_type":"plane","optimize_bbox":"memory","pin.location":{"lat":40,"lon":-70}}}` + if got != expected { + t.Errorf("expected\n%s\n,got:\n%s", expected, got) + } +} + +func TestGeoDistanceFilterWithGeoPoint(t *testing.T) { + f := NewGeoDistanceFilter("pin.location") + f = f.GeoPoint(GeoPointFromLatLon(40, -70)) + f = f.Distance("200km") + data, err := json.Marshal(f.Source()) + if err != nil { + t.Fatalf("marshaling to JSON failed: %v", err) + } + got := string(data) + expected := `{"geo_distance":{"distance":"200km","pin.location":{"lat":40,"lon":-70}}}` + if got != expected { + t.Errorf("expected\n%s\n,got:\n%s", expected, got) + } +} + +func TestGeoDistanceFilterWithGeoHash(t *testing.T) { + f := NewGeoDistanceFilter("pin.location") + f = f.GeoHash("drm3btev3e86") + f = f.Distance("12km") + data, err := json.Marshal(f.Source()) + if err != nil { + t.Fatalf("marshaling to JSON failed: %v", err) + } + got := string(data) + expected := `{"geo_distance":{"distance":"12km","pin.location":"drm3btev3e86"}}` + if got != expected { + t.Errorf("expected\n%s\n,got:\n%s", expected, got) + } +} diff --git a/_third_party/github.com/olivere/elastic/search_queries_fsq_score_funcs.go b/_third_party/github.com/olivere/elastic/search_queries_fsq_score_funcs.go index c75eac227b..7b51a1aad2 100644 --- a/_third_party/github.com/olivere/elastic/search_queries_fsq_score_funcs.go +++ b/_third_party/github.com/olivere/elastic/search_queries_fsq_score_funcs.go @@ -197,9 +197,10 @@ func (fn LinearDecayFunction) Source() interface{} { // -- Script -- type ScriptFunction struct { - script string - lang string - params map[string]interface{} + script string + scriptFile string + lang string + params map[string]interface{} } func NewScriptFunction(script string) ScriptFunction { @@ -218,6 +219,11 @@ func (fn ScriptFunction) Script(script string) ScriptFunction { return fn } +func (fn ScriptFunction) ScriptFile(scriptFile string) ScriptFunction { + fn.scriptFile = scriptFile + return fn +} + func (fn ScriptFunction) Lang(lang string) ScriptFunction { fn.lang = lang return fn @@ -235,7 +241,12 @@ func (fn ScriptFunction) Params(params map[string]interface{}) ScriptFunction { func (fn ScriptFunction) Source() interface{} { source := make(map[string]interface{}) - source["script"] = fn.script + if fn.script != "" { + source["script"] = fn.script + } + if fn.scriptFile != "" { + source["script_file"] = fn.scriptFile + } if fn.lang != "" { source["lang"] = fn.lang } diff --git a/_third_party/github.com/olivere/elastic/update.go b/_third_party/github.com/olivere/elastic/update.go index 04a3946535..92cea2da6f 100644 --- a/_third_party/github.com/olivere/elastic/update.go +++ b/_third_party/github.com/olivere/elastic/update.go @@ -35,6 +35,7 @@ type UpdateService struct { parent string script string scriptId string + scriptFile string scriptType string scriptLang string scriptParams map[string]interface{} @@ -100,12 +101,19 @@ func (b *UpdateService) Script(script string) *UpdateService { return b } -// ScriptID is the id of a stored script. +// ScriptId is the id of a stored script. func (b *UpdateService) ScriptId(scriptId string) *UpdateService { b.scriptId = scriptId return b } +// ScriptFile is the file name of a stored script. +// See https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html for details. +func (b *UpdateService) ScriptFile(scriptFile string) *UpdateService { + b.scriptFile = scriptFile + return b +} + func (b *UpdateService) ScriptType(scriptType string) *UpdateService { b.scriptType = scriptType return b @@ -276,6 +284,9 @@ func (b *UpdateService) body() (interface{}, error) { if b.scriptId != "" { source["script_id"] = b.scriptId } + if b.scriptFile != "" { + source["script_file"] = b.scriptFile + } if b.scriptLang != "" { source["lang"] = b.scriptLang } diff --git a/_third_party/github.com/olivere/elastic/update_test.go b/_third_party/github.com/olivere/elastic/update_test.go index bf74b71ed0..eb648eb0cd 100644 --- a/_third_party/github.com/olivere/elastic/update_test.go +++ b/_third_party/github.com/olivere/elastic/update_test.go @@ -88,6 +88,50 @@ func TestUpdateViaScriptId(t *testing.T) { } } +func TestUpdateViaScriptFile(t *testing.T) { + client := setupTestClient(t) + + scriptParams := map[string]interface{}{ + "pageViewEvent": map[string]interface{}{ + "url": "foo.com/bar", + "response": 404, + "time": "2014-01-01 12:32", + }, + } + + update := client.Update(). + Index("sessions").Type("session").Id("dh3sgudg8gsrgl"). + ScriptFile("update_script"). + ScriptedUpsert(true). + ScriptParams(scriptParams). + Upsert(map[string]interface{}{}) + path, params, err := update.url() + if err != nil { + t.Fatalf("expected to return URL, got: %v", err) + } + expectedPath := `/sessions/session/dh3sgudg8gsrgl/_update` + if expectedPath != path { + t.Errorf("expected URL path\n%s\ngot:\n%s", expectedPath, path) + } + expectedParams := url.Values{} + if expectedParams.Encode() != params.Encode() { + t.Errorf("expected URL parameters\n%s\ngot:\n%s", expectedParams.Encode(), params.Encode()) + } + body, err := update.body() + if err != nil { + t.Fatalf("expected to return body, got: %v", err) + } + data, err := json.Marshal(body) + if err != nil { + t.Fatalf("expected to marshal body as JSON, got: %v", err) + } + got := string(data) + expected := `{"params":{"pageViewEvent":{"response":404,"time":"2014-01-01 12:32","url":"foo.com/bar"}},"script_file":"update_script","scripted_upsert":true,"upsert":{}}` + if got != expected { + t.Errorf("expected\n%s\ngot:\n%s", expected, got) + } +} + func TestUpdateViaScriptAndUpsert(t *testing.T) { client := setupTestClient(t) update := client.Update(). diff --git a/_third_party/github.com/vaughan0/go-ini/LICENSE b/_third_party/github.com/vaughan0/go-ini/LICENSE new file mode 100644 index 0000000000..968b45384d --- /dev/null +++ b/_third_party/github.com/vaughan0/go-ini/LICENSE @@ -0,0 +1,14 @@ +Copyright (c) 2013 Vaughan Newton + +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. diff --git a/_third_party/github.com/vaughan0/go-ini/README.md b/_third_party/github.com/vaughan0/go-ini/README.md new file mode 100644 index 0000000000..d5cd4e74b0 --- /dev/null +++ b/_third_party/github.com/vaughan0/go-ini/README.md @@ -0,0 +1,70 @@ +go-ini +====== + +INI parsing library for Go (golang). + +View the API documentation [here](http://godoc.org/github.com/vaughan0/go-ini). + +Usage +----- + +Parse an INI file: + +```go +import "github.com/vaughan0/go-ini" + +file, err := ini.LoadFile("myfile.ini") +``` + +Get data from the parsed file: + +```go +name, ok := file.Get("person", "name") +if !ok { + panic("'name' variable missing from 'person' section") +} +``` + +Iterate through values in a section: + +```go +for key, value := range file["mysection"] { + fmt.Printf("%s => %s\n", key, value) +} +``` + +Iterate through sections in a file: + +```go +for name, section := range file { + fmt.Printf("Section name: %s\n", name) +} +``` + +File Format +----------- + +INI files are parsed by go-ini line-by-line. Each line may be one of the following: + + * A section definition: [section-name] + * A property: key = value + * A comment: #blahblah _or_ ;blahblah + * Blank. The line will be ignored. + +Properties defined before any section headers are placed in the default section, which has +the empty string as it's key. + +Example: + +```ini +# I am a comment +; So am I! + +[apples] +colour = red or green +shape = applish + +[oranges] +shape = square +colour = blue +``` diff --git a/_third_party/github.com/vaughan0/go-ini/ini.go b/_third_party/github.com/vaughan0/go-ini/ini.go new file mode 100644 index 0000000000..81aeb32f8b --- /dev/null +++ b/_third_party/github.com/vaughan0/go-ini/ini.go @@ -0,0 +1,123 @@ +// Package ini provides functions for parsing INI configuration files. +package ini + +import ( + "bufio" + "fmt" + "io" + "os" + "regexp" + "strings" +) + +var ( + sectionRegex = regexp.MustCompile(`^\[(.*)\]$`) + assignRegex = regexp.MustCompile(`^([^=]+)=(.*)$`) +) + +// ErrSyntax is returned when there is a syntax error in an INI file. +type ErrSyntax struct { + Line int + Source string // The contents of the erroneous line, without leading or trailing whitespace +} + +func (e ErrSyntax) Error() string { + return fmt.Sprintf("invalid INI syntax on line %d: %s", e.Line, e.Source) +} + +// A File represents a parsed INI file. +type File map[string]Section + +// A Section represents a single section of an INI file. +type Section map[string]string + +// Returns a named Section. A Section will be created if one does not already exist for the given name. +func (f File) Section(name string) Section { + section := f[name] + if section == nil { + section = make(Section) + f[name] = section + } + return section +} + +// Looks up a value for a key in a section and returns that value, along with a boolean result similar to a map lookup. +func (f File) Get(section, key string) (value string, ok bool) { + if s := f[section]; s != nil { + value, ok = s[key] + } + return +} + +// Loads INI data from a reader and stores the data in the File. +func (f File) Load(in io.Reader) (err error) { + bufin, ok := in.(*bufio.Reader) + if !ok { + bufin = bufio.NewReader(in) + } + return parseFile(bufin, f) +} + +// Loads INI data from a named file and stores the data in the File. +func (f File) LoadFile(file string) (err error) { + in, err := os.Open(file) + if err != nil { + return + } + defer in.Close() + return f.Load(in) +} + +func parseFile(in *bufio.Reader, file File) (err error) { + section := "" + lineNum := 0 + for done := false; !done; { + var line string + if line, err = in.ReadString('\n'); err != nil { + if err == io.EOF { + done = true + } else { + return + } + } + lineNum++ + line = strings.TrimSpace(line) + if len(line) == 0 { + // Skip blank lines + continue + } + if line[0] == ';' || line[0] == '#' { + // Skip comments + continue + } + + if groups := assignRegex.FindStringSubmatch(line); groups != nil { + key, val := groups[1], groups[2] + key, val = strings.TrimSpace(key), strings.TrimSpace(val) + file.Section(section)[key] = val + } else if groups := sectionRegex.FindStringSubmatch(line); groups != nil { + name := strings.TrimSpace(groups[1]) + section = name + // Create the section if it does not exist + file.Section(section) + } else { + return ErrSyntax{lineNum, line} + } + + } + return nil +} + +// Loads and returns a File from a reader. +func Load(in io.Reader) (File, error) { + file := make(File) + err := file.Load(in) + return file, err +} + +// Loads and returns an INI File from a file on disk. +func LoadFile(filename string) (File, error) { + file := make(File) + err := file.LoadFile(filename) + return file, err +} diff --git a/_third_party/github.com/vaughan0/go-ini/ini_linux_test.go b/_third_party/github.com/vaughan0/go-ini/ini_linux_test.go new file mode 100644 index 0000000000..38a6f0004c --- /dev/null +++ b/_third_party/github.com/vaughan0/go-ini/ini_linux_test.go @@ -0,0 +1,43 @@ +package ini + +import ( + "reflect" + "syscall" + "testing" +) + +func TestLoadFile(t *testing.T) { + originalOpenFiles := numFilesOpen(t) + + file, err := LoadFile("test.ini") + if err != nil { + t.Fatal(err) + } + + if originalOpenFiles != numFilesOpen(t) { + t.Error("test.ini not closed") + } + + if !reflect.DeepEqual(file, File{"default": {"stuff": "things"}}) { + t.Error("file not read correctly") + } +} + +func numFilesOpen(t *testing.T) (num uint64) { + var rlimit syscall.Rlimit + err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit) + if err != nil { + t.Fatal(err) + } + maxFds := int(rlimit.Cur) + + var stat syscall.Stat_t + for i := 0; i < maxFds; i++ { + if syscall.Fstat(i, &stat) == nil { + num++ + } else { + return + } + } + return +} diff --git a/_third_party/github.com/vaughan0/go-ini/ini_test.go b/_third_party/github.com/vaughan0/go-ini/ini_test.go new file mode 100644 index 0000000000..06a4d05eaf --- /dev/null +++ b/_third_party/github.com/vaughan0/go-ini/ini_test.go @@ -0,0 +1,89 @@ +package ini + +import ( + "reflect" + "strings" + "testing" +) + +func TestLoad(t *testing.T) { + src := ` + # Comments are ignored + + herp = derp + + [foo] + hello=world + whitespace should = not matter + ; sneaky semicolon-style comment + multiple = equals = signs + + [bar] + this = that` + + file, err := Load(strings.NewReader(src)) + if err != nil { + t.Fatal(err) + } + check := func(section, key, expect string) { + if value, _ := file.Get(section, key); value != expect { + t.Errorf("Get(%q, %q): expected %q, got %q", section, key, expect, value) + } + } + + check("", "herp", "derp") + check("foo", "hello", "world") + check("foo", "whitespace should", "not matter") + check("foo", "multiple", "equals = signs") + check("bar", "this", "that") +} + +func TestSyntaxError(t *testing.T) { + src := ` + # Line 2 + [foo] + bar = baz + # Here's an error on line 6: + wut? + herp = derp` + _, err := Load(strings.NewReader(src)) + t.Logf("%T: %v", err, err) + if err == nil { + t.Fatal("expected an error, got nil") + } + syntaxErr, ok := err.(ErrSyntax) + if !ok { + t.Fatal("expected an error of type ErrSyntax") + } + if syntaxErr.Line != 6 { + t.Fatal("incorrect line number") + } + if syntaxErr.Source != "wut?" { + t.Fatal("incorrect source") + } +} + +func TestDefinedSectionBehaviour(t *testing.T) { + check := func(src string, expect File) { + file, err := Load(strings.NewReader(src)) + if err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(file, expect) { + t.Errorf("expected %v, got %v", expect, file) + } + } + // No sections for an empty file + check("", File{}) + // Default section only if there are actually values for it + check("foo=bar", File{"": {"foo": "bar"}}) + // User-defined sections should always be present, even if empty + check("[a]\n[b]\nfoo=bar", File{ + "a": {}, + "b": {"foo": "bar"}, + }) + check("foo=bar\n[a]\nthis=that", File{ + "": {"foo": "bar"}, + "a": {"this": "that"}, + }) +} diff --git a/_third_party/github.com/vaughan0/go-ini/test.ini b/_third_party/github.com/vaughan0/go-ini/test.ini new file mode 100644 index 0000000000..d13c999e25 --- /dev/null +++ b/_third_party/github.com/vaughan0/go-ini/test.ini @@ -0,0 +1,2 @@ +[default] +stuff = things diff --git a/_third_party/github.com/vdobler/chart/stat.go b/_third_party/github.com/vdobler/chart/stat.go old mode 100755 new mode 100644