diff --git a/cmd/wof-sqlite-index-example/main.go b/cmd/wof-sqlite-index-example/main.go index 3e256ff..a919c59 100644 --- a/cmd/wof-sqlite-index-example/main.go +++ b/cmd/wof-sqlite-index-example/main.go @@ -12,8 +12,6 @@ import ( "github.com/whosonfirst/go-whosonfirst-sqlite-index" "github.com/whosonfirst/go-whosonfirst-sqlite/database" "github.com/whosonfirst/go-whosonfirst-sqlite/tables" - "github.com/whosonfirst/go-reader" - _ "github.com/whosonfirst/go-reader-http" "io" "os" "strings" @@ -37,13 +35,10 @@ func main() { live_hard := flag.Bool("live-hard-die-fast", true, "Enable various performance-related pragmas at the expense of possible (unlikely) database corruption") timings := flag.Bool("timings", false, "Display timings during and after indexing") - index_belongsto := flag.Bool("index-belongs-to", false, "Index wof:belongsto records for each feature") - belongsto_reader_uri := flag.String("belongs-to-uri", "", "A valid whosonfirst/go-reader Reader URI for reading wof:belongsto records") + post_index := flag.Bool("post-index", false, "Enable post indexing callback function") flag.Parse() - ctx := context.Background() - logger := log.SimpleWOFLogger() stdout := io.Writer(os.Stdout) @@ -76,7 +71,7 @@ func main() { to_index = append(to_index, ex) - cb := func(ctx context.Context, fh io.Reader, args ...interface{}) (interface{}, error) { + record_func := func(ctx context.Context, fh io.Reader, args ...interface{}) (interface{}, error) { now := time.Now() @@ -88,23 +83,21 @@ func main() { } idx_opts := &index.SQLiteIndexerOptions{ - DB: db, - Tables: to_index, - Callback: cb, + DB: db, + Tables: to_index, + LoadRecordFunc: record_func, } - if *index_belongsto { + if *post_index { - r, err := reader.NewReader(ctx, *belongsto_reader_uri) - - if err != nil { - logger.Fatal("Failed to create Reader (%s), %v", *belongsto_reader_uri, err) + post_func := func(ctx context.Context, db sqlite.Database, tables []sqlite.Table, record interface{}) error { + logger.Status("Post index func w/ %v", record) + return nil } - idx_opts.IndexBelongsTo = true - idx_opts.BelongsToReader = r + idx_opts.PostIndexFunc = post_func } - + idx, err := index.NewSQLiteIndexer(idx_opts) if err != nil { diff --git a/go.mod b/go.mod index dc9387f..56ab045 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,14 @@ module github.com/whosonfirst/go-whosonfirst-sqlite-index go 1.12 require ( - github.com/whosonfirst/go-reader v0.1.1 - github.com/whosonfirst/go-reader-http v0.0.2 - github.com/whosonfirst/go-whosonfirst-geojson-v2 v0.12.2 + github.com/whosonfirst/go-reader v0.1.1 // indirect + github.com/whosonfirst/go-reader-http v0.0.2 // indirect + github.com/whosonfirst/go-whosonfirst-geojson-v2 v0.12.2 // indirect github.com/whosonfirst/go-whosonfirst-index v0.2.3 github.com/whosonfirst/go-whosonfirst-index-csv v0.0.0-20191002171239-c6712fe20972 github.com/whosonfirst/go-whosonfirst-index-sqlite v0.0.3 github.com/whosonfirst/go-whosonfirst-log v0.1.0 - github.com/whosonfirst/go-whosonfirst-reader v0.0.1 + github.com/whosonfirst/go-whosonfirst-reader v0.0.1 // indirect github.com/whosonfirst/go-whosonfirst-sqlite v0.1.5 - github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.7 + github.com/whosonfirst/go-whosonfirst-sqlite-features v0.2.7 // indirect ) diff --git a/index.go b/index.go index dca5da7..8fe4e9e 100644 --- a/index.go +++ b/index.go @@ -2,22 +2,18 @@ package index import ( "context" - "fmt" - "github.com/whosonfirst/go-reader" - "github.com/whosonfirst/go-whosonfirst-geojson-v2" - "github.com/whosonfirst/go-whosonfirst-geojson-v2/properties/whosonfirst" wof_index "github.com/whosonfirst/go-whosonfirst-index" "github.com/whosonfirst/go-whosonfirst-log" - wof_reader "github.com/whosonfirst/go-whosonfirst-reader" "github.com/whosonfirst/go-whosonfirst-sqlite" - wof_tables "github.com/whosonfirst/go-whosonfirst-sqlite-features/tables" "io" "sync" "sync/atomic" "time" ) -type SQLiteIndexerFunc func(context.Context, io.Reader, ...interface{}) (interface{}, error) +type SQLiteIndexerPostIndexFunc func(context.Context, sqlite.Database, []sqlite.Table, interface{}) error + +type SQLiteIndexerLoadRecordFunc func(context.Context, io.Reader, ...interface{}) (interface{}, error) type SQLiteIndexer struct { callback wof_index.IndexerFunc @@ -28,18 +24,17 @@ type SQLiteIndexer struct { } type SQLiteIndexerOptions struct { - DB sqlite.Database - Tables []sqlite.Table - Callback SQLiteIndexerFunc - IndexBelongsTo bool - BelongsToReader reader.Reader + DB sqlite.Database + Tables []sqlite.Table + LoadRecordFunc SQLiteIndexerLoadRecordFunc + PostIndexFunc SQLiteIndexerPostIndexFunc } func NewSQLiteIndexer(opts *SQLiteIndexerOptions) (*SQLiteIndexer, error) { db := opts.DB tables := opts.Tables - callback := opts.Callback + record_func := opts.LoadRecordFunc table_timings := make(map[string]time.Duration) mu := new(sync.RWMutex) @@ -54,7 +49,7 @@ func NewSQLiteIndexer(opts *SQLiteIndexerOptions) (*SQLiteIndexer, error) { return err } - record, err := callback(ctx, fh, args...) + record, err := record_func(ctx, fh, args...) if err != nil { logger.Warning("failed to load record (%s) because %s", path, err) @@ -97,61 +92,13 @@ func NewSQLiteIndexer(opts *SQLiteIndexerOptions) (*SQLiteIndexer, error) { mu.Unlock() } - if opts.IndexBelongsTo { + if opts.PostIndexFunc != nil { - geojson_t, err := wof_tables.NewGeoJSONTable() + err := opts.PostIndexFunc(ctx, db, tables, record) if err != nil { return err } - - conn, err := db.Conn() - - if err != nil { - return err - } - - f := record.(geojson.Feature) - belongsto := whosonfirst.BelongsTo(f) - - to_index := make([]geojson.Feature, 0) - - for _, id := range belongsto { - - sql := fmt.Sprintf("SELECT COUNT(id) FROM %s WHERE id=?", geojson_t.Name()) - row := conn.QueryRow(sql, id) - - var count int - err = row.Scan(&count) - - if err != nil { - return err - } - - if count == 0 { - - ancestor, err := wof_reader.LoadFeatureFromID(ctx, opts.BelongsToReader, id) - - if err != nil { - return err - } - - to_index = append(to_index, ancestor) - } - } - - for _, record := range to_index { - - for _, t := range tables { - - err = t.IndexRecord(db, record) - - if err != nil { - return err - } - } - } - } return nil diff --git a/vendor/github.com/aaronland/go-roster/.gitignore b/vendor/github.com/aaronland/go-roster/.gitignore deleted file mode 100644 index e4e5f6c..0000000 --- a/vendor/github.com/aaronland/go-roster/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*~ \ No newline at end of file diff --git a/vendor/github.com/aaronland/go-roster/LICENSE b/vendor/github.com/aaronland/go-roster/LICENSE deleted file mode 100644 index 29b6a83..0000000 --- a/vendor/github.com/aaronland/go-roster/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2019, Aaron Straup Cope -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the {organization} nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/aaronland/go-roster/README.md b/vendor/github.com/aaronland/go-roster/README.md deleted file mode 100644 index 66ad731..0000000 --- a/vendor/github.com/aaronland/go-roster/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# go-roster - diff --git a/vendor/github.com/aaronland/go-roster/default.go b/vendor/github.com/aaronland/go-roster/default.go deleted file mode 100644 index 43c51cd..0000000 --- a/vendor/github.com/aaronland/go-roster/default.go +++ /dev/null @@ -1,92 +0,0 @@ -package roster - -import ( - "context" - "errors" - "sort" - "strings" - "sync" -) - -type DefaultRoster struct { - Roster - mu *sync.RWMutex - drivers map[string]interface{} -} - -func NewDefaultRoster() (Roster, error) { - - mu := new(sync.RWMutex) - drivers := make(map[string]interface{}) - - dr := &DefaultRoster{ - mu: mu, - drivers: drivers, - } - - return dr, nil -} - -func (dr *DefaultRoster) Driver(ctx context.Context, name string) (interface{}, error) { - - nrml_name := dr.NormalizeName(ctx, name) - - dr.mu.Lock() - defer dr.mu.Unlock() - - i, ok := dr.drivers[nrml_name] - - if !ok { - return nil, errors.New("Unknown driver") - } - - return i, nil -} - -func (dr *DefaultRoster) Register(ctx context.Context, name string, i interface{}) error { - - dr.mu.Lock() - defer dr.mu.Unlock() - - if i == nil { - return errors.New("Nothing to register") - } - - nrml_name := dr.NormalizeName(ctx, name) - - _, dup := dr.drivers[nrml_name] - - if dup { - return errors.New("Register called twice for reader " + name) - } - - dr.drivers[nrml_name] = i - return nil -} - -func (dr *DefaultRoster) UnregisterAll(ctx context.Context) error { - dr.mu.Lock() - defer dr.mu.Unlock() - - dr.drivers = make(map[string]interface{}) - return nil -} - -func (dr *DefaultRoster) NormalizeName(ctx context.Context, name string) string { - return strings.ToUpper(name) -} - -func (dr *DefaultRoster) Drivers(ctx context.Context) []string { - - dr.mu.RLock() - defer dr.mu.RUnlock() - - var list []string - - for name := range dr.drivers { - list = append(list, name) - } - - sort.Strings(list) - return list -} diff --git a/vendor/github.com/aaronland/go-roster/go.mod b/vendor/github.com/aaronland/go-roster/go.mod deleted file mode 100644 index eda0061..0000000 --- a/vendor/github.com/aaronland/go-roster/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/aaronland/go-roster - -go 1.12 diff --git a/vendor/github.com/aaronland/go-roster/roster.go b/vendor/github.com/aaronland/go-roster/roster.go deleted file mode 100644 index c667e72..0000000 --- a/vendor/github.com/aaronland/go-roster/roster.go +++ /dev/null @@ -1,13 +0,0 @@ -package roster - -import ( - "context" -) - -type Roster interface { - Driver(context.Context, string) (interface{}, error) - Drivers(context.Context) []string - UnregisterAll(context.Context) error - NormalizeName(context.Context, string) string - Register(context.Context, string, interface{}) error -} diff --git a/vendor/github.com/hashicorp/errwrap/LICENSE b/vendor/github.com/hashicorp/errwrap/LICENSE deleted file mode 100644 index c33dcc7..0000000 --- a/vendor/github.com/hashicorp/errwrap/LICENSE +++ /dev/null @@ -1,354 +0,0 @@ -Mozilla Public License, version 2.0 - -1. Definitions - -1.1. “Contributor” - - means each individual or legal entity that creates, contributes to the - creation of, or owns Covered Software. - -1.2. “Contributor Version” - - means the combination of the Contributions of others (if any) used by a - Contributor and that particular Contributor’s Contribution. - -1.3. “Contribution” - - means Covered Software of a particular Contributor. - -1.4. “Covered Software” - - means Source Code Form to which the initial Contributor has attached the - notice in Exhibit A, the Executable Form of such Source Code Form, and - Modifications of such Source Code Form, in each case including portions - thereof. - -1.5. “Incompatible With Secondary Licenses” - means - - a. that the initial Contributor has attached the notice described in - Exhibit B to the Covered Software; or - - b. that the Covered Software was made available under the terms of version - 1.1 or earlier of the License, but not also under the terms of a - Secondary License. - -1.6. “Executable Form” - - means any form of the work other than Source Code Form. - -1.7. “Larger Work” - - means a work that combines Covered Software with other material, in a separate - file or files, that is not Covered Software. - -1.8. “License” - - means this document. - -1.9. “Licensable” - - means having the right to grant, to the maximum extent possible, whether at the - time of the initial grant or subsequently, any and all of the rights conveyed by - this License. - -1.10. “Modifications” - - means any of the following: - - a. any file in Source Code Form that results from an addition to, deletion - from, or modification of the contents of Covered Software; or - - b. any new file in Source Code Form that contains any Covered Software. - -1.11. “Patent Claims” of a Contributor - - means any patent claim(s), including without limitation, method, process, - and apparatus claims, in any patent Licensable by such Contributor that - would be infringed, but for the grant of the License, by the making, - using, selling, offering for sale, having made, import, or transfer of - either its Contributions or its Contributor Version. - -1.12. “Secondary License” - - means either the GNU General Public License, Version 2.0, the GNU Lesser - General Public License, Version 2.1, the GNU Affero General Public - License, Version 3.0, or any later versions of those licenses. - -1.13. “Source Code Form” - - means the form of the work preferred for making modifications. - -1.14. “You” (or “Your”) - - means an individual or a legal entity exercising rights under this - License. For legal entities, “You” includes any entity that controls, is - controlled by, or is under common control with You. For purposes of this - definition, “control” means (a) the power, direct or indirect, to cause - the direction or management of such entity, whether by contract or - otherwise, or (b) ownership of more than fifty percent (50%) of the - outstanding shares or beneficial ownership of such entity. - - -2. License Grants and Conditions - -2.1. Grants - - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - a. under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or as - part of a Larger Work; and - - b. under Patent Claims of such Contributor to make, use, sell, offer for - sale, have made, import, and otherwise transfer either its Contributions - or its Contributor Version. - -2.2. Effective Date - - The licenses granted in Section 2.1 with respect to any Contribution become - effective for each Contribution on the date the Contributor first distributes - such Contribution. - -2.3. Limitations on Grant Scope - - The licenses granted in this Section 2 are the only rights granted under this - License. No additional rights or licenses will be implied from the distribution - or licensing of Covered Software under this License. Notwithstanding Section - 2.1(b) above, no patent license is granted by a Contributor: - - a. for any code that a Contributor has removed from Covered Software; or - - b. for infringements caused by: (i) Your and any other third party’s - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - - c. under Patent Claims infringed by Covered Software in the absence of its - Contributions. - - This License does not grant any rights in the trademarks, service marks, or - logos of any Contributor (except as may be necessary to comply with the - notice requirements in Section 3.4). - -2.4. Subsequent Licenses - - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this License - (see Section 10.2) or under the terms of a Secondary License (if permitted - under the terms of Section 3.3). - -2.5. Representation - - Each Contributor represents that the Contributor believes its Contributions - are its original creation(s) or it has sufficient rights to grant the - rights to its Contributions conveyed by this License. - -2.6. Fair Use - - This License is not intended to limit any rights You have under applicable - copyright doctrines of fair use, fair dealing, or other equivalents. - -2.7. Conditions - - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in - Section 2.1. - - -3. Responsibilities - -3.1. Distribution of Source Form - - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under the - terms of this License. You must inform recipients that the Source Code Form - of the Covered Software is governed by the terms of this License, and how - they can obtain a copy of this License. You may not attempt to alter or - restrict the recipients’ rights in the Source Code Form. - -3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - a. such Covered Software must also be made available in Source Code Form, - as described in Section 3.1, and You must inform recipients of the - Executable Form how they can obtain a copy of such Source Code Form by - reasonable means in a timely manner, at a charge no more than the cost - of distribution to the recipient; and - - b. You may distribute such Executable Form under the terms of this License, - or sublicense it under different terms, provided that the license for - the Executable Form does not attempt to limit or alter the recipients’ - rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for the - Covered Software. If the Larger Work is a combination of Covered Software - with a work governed by one or more Secondary Licenses, and the Covered - Software is not Incompatible With Secondary Licenses, this License permits - You to additionally distribute such Covered Software under the terms of - such Secondary License(s), so that the recipient of the Larger Work may, at - their option, further distribute the Covered Software under the terms of - either this License or such Secondary License(s). - -3.4. Notices - - You may not remove or alter the substance of any license notices (including - copyright notices, patent notices, disclaimers of warranty, or limitations - of liability) contained within the Source Code Form of the Covered - Software, except that You may alter any license notices to the extent - required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on behalf - of any Contributor. You must make it absolutely clear that any such - warranty, support, indemnity, or liability obligation is offered by You - alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - -4. Inability to Comply Due to Statute or Regulation - - If it is impossible for You to comply with any of the terms of this License - with respect to some or all of the Covered Software due to statute, judicial - order, or regulation then You must: (a) comply with the terms of this License - to the maximum extent possible; and (b) describe the limitations and the code - they affect. Such description must be placed in a text file included with all - distributions of the Covered Software under this License. Except to the - extent prohibited by statute or regulation, such description must be - sufficiently detailed for a recipient of ordinary skill to be able to - understand it. - -5. Termination - -5.1. The rights granted under this License will terminate automatically if You - fail to comply with any of its terms. However, if You become compliant, - then the rights granted under this License from a particular Contributor - are reinstated (a) provisionally, unless and until such Contributor - explicitly and finally terminates Your grants, and (b) on an ongoing basis, - if such Contributor fails to notify You of the non-compliance by some - reasonable means prior to 60 days after You have come back into compliance. - Moreover, Your grants from a particular Contributor are reinstated on an - ongoing basis if such Contributor notifies You of the non-compliance by - some reasonable means, this is the first time You have received notice of - non-compliance with this License from such Contributor, and You become - compliant prior to 30 days after Your receipt of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent - infringement claim (excluding declaratory judgment actions, counter-claims, - and cross-claims) alleging that a Contributor Version directly or - indirectly infringes any patent, then the rights granted to You by any and - all Contributors for the Covered Software under Section 2.1 of this License - shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user - license agreements (excluding distributors and resellers) which have been - validly granted by You or Your distributors under this License prior to - termination shall survive termination. - -6. Disclaimer of Warranty - - Covered Software is provided under this License on an “as is” basis, without - warranty of any kind, either expressed, implied, or statutory, including, - without limitation, warranties that the Covered Software is free of defects, - merchantable, fit for a particular purpose or non-infringing. The entire - risk as to the quality and performance of the Covered Software is with You. - Should any Covered Software prove defective in any respect, You (not any - Contributor) assume the cost of any necessary servicing, repair, or - correction. This disclaimer of warranty constitutes an essential part of this - License. No use of any Covered Software is authorized under this License - except under this disclaimer. - -7. Limitation of Liability - - Under no circumstances and under no legal theory, whether tort (including - negligence), contract, or otherwise, shall any Contributor, or anyone who - distributes Covered Software as permitted above, be liable to You for any - direct, indirect, special, incidental, or consequential damages of any - character including, without limitation, damages for lost profits, loss of - goodwill, work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses, even if such party shall have been - informed of the possibility of such damages. This limitation of liability - shall not apply to liability for death or personal injury resulting from such - party’s negligence to the extent applicable law prohibits such limitation. - Some jurisdictions do not allow the exclusion or limitation of incidental or - consequential damages, so this exclusion and limitation may not apply to You. - -8. Litigation - - Any litigation relating to this License may be brought only in the courts of - a jurisdiction where the defendant maintains its principal place of business - and such litigation shall be governed by laws of that jurisdiction, without - reference to its conflict-of-law provisions. Nothing in this Section shall - prevent a party’s ability to bring cross-claims or counter-claims. - -9. Miscellaneous - - This License represents the complete agreement concerning the subject matter - hereof. If any provision of this License is held to be unenforceable, such - provision shall be reformed only to the extent necessary to make it - enforceable. Any law or regulation which provides that the language of a - contract shall be construed against the drafter shall not be used to construe - this License against a Contributor. - - -10. Versions of the License - -10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - -10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version of - the License under which You originally received the Covered Software, or - under the terms of any subsequent version published by the license - steward. - -10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a modified - version of this License if you rename the license and remove any - references to the name of the license steward (except to note that such - modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses - If You choose to distribute Source Code Form that is Incompatible With - Secondary Licenses under the terms of this version of the License, the - notice described in Exhibit B of this License must be attached. - -Exhibit A - Source Code Form License Notice - - This Source Code Form is subject to the - terms of the Mozilla Public License, v. - 2.0. If a copy of the MPL was not - distributed with this file, You can - obtain one at - http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular file, then -You may include the notice in a location (such as a LICENSE file in a relevant -directory) where a recipient would be likely to look for such a notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - “Incompatible With Secondary Licenses” Notice - - This Source Code Form is “Incompatible - With Secondary Licenses”, as defined by - the Mozilla Public License, v. 2.0. - diff --git a/vendor/github.com/hashicorp/errwrap/README.md b/vendor/github.com/hashicorp/errwrap/README.md deleted file mode 100644 index 1c95f59..0000000 --- a/vendor/github.com/hashicorp/errwrap/README.md +++ /dev/null @@ -1,89 +0,0 @@ -# errwrap - -`errwrap` is a package for Go that formalizes the pattern of wrapping errors -and checking if an error contains another error. - -There is a common pattern in Go of taking a returned `error` value and -then wrapping it (such as with `fmt.Errorf`) before returning it. The problem -with this pattern is that you completely lose the original `error` structure. - -Arguably the _correct_ approach is that you should make a custom structure -implementing the `error` interface, and have the original error as a field -on that structure, such [as this example](http://golang.org/pkg/os/#PathError). -This is a good approach, but you have to know the entire chain of possible -rewrapping that happens, when you might just care about one. - -`errwrap` formalizes this pattern (it doesn't matter what approach you use -above) by giving a single interface for wrapping errors, checking if a specific -error is wrapped, and extracting that error. - -## Installation and Docs - -Install using `go get github.com/hashicorp/errwrap`. - -Full documentation is available at -http://godoc.org/github.com/hashicorp/errwrap - -## Usage - -#### Basic Usage - -Below is a very basic example of its usage: - -```go -// A function that always returns an error, but wraps it, like a real -// function might. -func tryOpen() error { - _, err := os.Open("/i/dont/exist") - if err != nil { - return errwrap.Wrapf("Doesn't exist: {{err}}", err) - } - - return nil -} - -func main() { - err := tryOpen() - - // We can use the Contains helpers to check if an error contains - // another error. It is safe to do this with a nil error, or with - // an error that doesn't even use the errwrap package. - if errwrap.Contains(err, ErrNotExist) { - // Do something - } - if errwrap.ContainsType(err, new(os.PathError)) { - // Do something - } - - // Or we can use the associated `Get` functions to just extract - // a specific error. This would return nil if that specific error doesn't - // exist. - perr := errwrap.GetType(err, new(os.PathError)) -} -``` - -#### Custom Types - -If you're already making custom types that properly wrap errors, then -you can get all the functionality of `errwraps.Contains` and such by -implementing the `Wrapper` interface with just one function. Example: - -```go -type AppError { - Code ErrorCode - Err error -} - -func (e *AppError) WrappedErrors() []error { - return []error{e.Err} -} -``` - -Now this works: - -```go -err := &AppError{Err: fmt.Errorf("an error")} -if errwrap.ContainsType(err, fmt.Errorf("")) { - // This will work! -} -``` diff --git a/vendor/github.com/hashicorp/errwrap/errwrap.go b/vendor/github.com/hashicorp/errwrap/errwrap.go deleted file mode 100644 index a733bef..0000000 --- a/vendor/github.com/hashicorp/errwrap/errwrap.go +++ /dev/null @@ -1,169 +0,0 @@ -// Package errwrap implements methods to formalize error wrapping in Go. -// -// All of the top-level functions that take an `error` are built to be able -// to take any error, not just wrapped errors. This allows you to use errwrap -// without having to type-check and type-cast everywhere. -package errwrap - -import ( - "errors" - "reflect" - "strings" -) - -// WalkFunc is the callback called for Walk. -type WalkFunc func(error) - -// Wrapper is an interface that can be implemented by custom types to -// have all the Contains, Get, etc. functions in errwrap work. -// -// When Walk reaches a Wrapper, it will call the callback for every -// wrapped error in addition to the wrapper itself. Since all the top-level -// functions in errwrap use Walk, this means that all those functions work -// with your custom type. -type Wrapper interface { - WrappedErrors() []error -} - -// Wrap defines that outer wraps inner, returning an error type that -// can be cleanly used with the other methods in this package, such as -// Contains, GetAll, etc. -// -// This function won't modify the error message at all (the outer message -// will be used). -func Wrap(outer, inner error) error { - return &wrappedError{ - Outer: outer, - Inner: inner, - } -} - -// Wrapf wraps an error with a formatting message. This is similar to using -// `fmt.Errorf` to wrap an error. If you're using `fmt.Errorf` to wrap -// errors, you should replace it with this. -// -// format is the format of the error message. The string '{{err}}' will -// be replaced with the original error message. -func Wrapf(format string, err error) error { - outerMsg := "" - if err != nil { - outerMsg = err.Error() - } - - outer := errors.New(strings.Replace( - format, "{{err}}", outerMsg, -1)) - - return Wrap(outer, err) -} - -// Contains checks if the given error contains an error with the -// message msg. If err is not a wrapped error, this will always return -// false unless the error itself happens to match this msg. -func Contains(err error, msg string) bool { - return len(GetAll(err, msg)) > 0 -} - -// ContainsType checks if the given error contains an error with -// the same concrete type as v. If err is not a wrapped error, this will -// check the err itself. -func ContainsType(err error, v interface{}) bool { - return len(GetAllType(err, v)) > 0 -} - -// Get is the same as GetAll but returns the deepest matching error. -func Get(err error, msg string) error { - es := GetAll(err, msg) - if len(es) > 0 { - return es[len(es)-1] - } - - return nil -} - -// GetType is the same as GetAllType but returns the deepest matching error. -func GetType(err error, v interface{}) error { - es := GetAllType(err, v) - if len(es) > 0 { - return es[len(es)-1] - } - - return nil -} - -// GetAll gets all the errors that might be wrapped in err with the -// given message. The order of the errors is such that the outermost -// matching error (the most recent wrap) is index zero, and so on. -func GetAll(err error, msg string) []error { - var result []error - - Walk(err, func(err error) { - if err.Error() == msg { - result = append(result, err) - } - }) - - return result -} - -// GetAllType gets all the errors that are the same type as v. -// -// The order of the return value is the same as described in GetAll. -func GetAllType(err error, v interface{}) []error { - var result []error - - var search string - if v != nil { - search = reflect.TypeOf(v).String() - } - Walk(err, func(err error) { - var needle string - if err != nil { - needle = reflect.TypeOf(err).String() - } - - if needle == search { - result = append(result, err) - } - }) - - return result -} - -// Walk walks all the wrapped errors in err and calls the callback. If -// err isn't a wrapped error, this will be called once for err. If err -// is a wrapped error, the callback will be called for both the wrapper -// that implements error as well as the wrapped error itself. -func Walk(err error, cb WalkFunc) { - if err == nil { - return - } - - switch e := err.(type) { - case *wrappedError: - cb(e.Outer) - Walk(e.Inner, cb) - case Wrapper: - cb(err) - - for _, err := range e.WrappedErrors() { - Walk(err, cb) - } - default: - cb(err) - } -} - -// wrappedError is an implementation of error that has both the -// outer and inner errors. -type wrappedError struct { - Outer error - Inner error -} - -func (w *wrappedError) Error() string { - return w.Outer.Error() -} - -func (w *wrappedError) WrappedErrors() []error { - return []error{w.Outer, w.Inner} -} diff --git a/vendor/github.com/hashicorp/go-multierror/LICENSE b/vendor/github.com/hashicorp/go-multierror/LICENSE deleted file mode 100644 index 82b4de9..0000000 --- a/vendor/github.com/hashicorp/go-multierror/LICENSE +++ /dev/null @@ -1,353 +0,0 @@ -Mozilla Public License, version 2.0 - -1. Definitions - -1.1. “Contributor” - - means each individual or legal entity that creates, contributes to the - creation of, or owns Covered Software. - -1.2. “Contributor Version” - - means the combination of the Contributions of others (if any) used by a - Contributor and that particular Contributor’s Contribution. - -1.3. “Contribution” - - means Covered Software of a particular Contributor. - -1.4. “Covered Software” - - means Source Code Form to which the initial Contributor has attached the - notice in Exhibit A, the Executable Form of such Source Code Form, and - Modifications of such Source Code Form, in each case including portions - thereof. - -1.5. “Incompatible With Secondary Licenses” - means - - a. that the initial Contributor has attached the notice described in - Exhibit B to the Covered Software; or - - b. that the Covered Software was made available under the terms of version - 1.1 or earlier of the License, but not also under the terms of a - Secondary License. - -1.6. “Executable Form” - - means any form of the work other than Source Code Form. - -1.7. “Larger Work” - - means a work that combines Covered Software with other material, in a separate - file or files, that is not Covered Software. - -1.8. “License” - - means this document. - -1.9. “Licensable” - - means having the right to grant, to the maximum extent possible, whether at the - time of the initial grant or subsequently, any and all of the rights conveyed by - this License. - -1.10. “Modifications” - - means any of the following: - - a. any file in Source Code Form that results from an addition to, deletion - from, or modification of the contents of Covered Software; or - - b. any new file in Source Code Form that contains any Covered Software. - -1.11. “Patent Claims” of a Contributor - - means any patent claim(s), including without limitation, method, process, - and apparatus claims, in any patent Licensable by such Contributor that - would be infringed, but for the grant of the License, by the making, - using, selling, offering for sale, having made, import, or transfer of - either its Contributions or its Contributor Version. - -1.12. “Secondary License” - - means either the GNU General Public License, Version 2.0, the GNU Lesser - General Public License, Version 2.1, the GNU Affero General Public - License, Version 3.0, or any later versions of those licenses. - -1.13. “Source Code Form” - - means the form of the work preferred for making modifications. - -1.14. “You” (or “Your”) - - means an individual or a legal entity exercising rights under this - License. For legal entities, “You” includes any entity that controls, is - controlled by, or is under common control with You. For purposes of this - definition, “control” means (a) the power, direct or indirect, to cause - the direction or management of such entity, whether by contract or - otherwise, or (b) ownership of more than fifty percent (50%) of the - outstanding shares or beneficial ownership of such entity. - - -2. License Grants and Conditions - -2.1. Grants - - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - a. under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or as - part of a Larger Work; and - - b. under Patent Claims of such Contributor to make, use, sell, offer for - sale, have made, import, and otherwise transfer either its Contributions - or its Contributor Version. - -2.2. Effective Date - - The licenses granted in Section 2.1 with respect to any Contribution become - effective for each Contribution on the date the Contributor first distributes - such Contribution. - -2.3. Limitations on Grant Scope - - The licenses granted in this Section 2 are the only rights granted under this - License. No additional rights or licenses will be implied from the distribution - or licensing of Covered Software under this License. Notwithstanding Section - 2.1(b) above, no patent license is granted by a Contributor: - - a. for any code that a Contributor has removed from Covered Software; or - - b. for infringements caused by: (i) Your and any other third party’s - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - - c. under Patent Claims infringed by Covered Software in the absence of its - Contributions. - - This License does not grant any rights in the trademarks, service marks, or - logos of any Contributor (except as may be necessary to comply with the - notice requirements in Section 3.4). - -2.4. Subsequent Licenses - - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this License - (see Section 10.2) or under the terms of a Secondary License (if permitted - under the terms of Section 3.3). - -2.5. Representation - - Each Contributor represents that the Contributor believes its Contributions - are its original creation(s) or it has sufficient rights to grant the - rights to its Contributions conveyed by this License. - -2.6. Fair Use - - This License is not intended to limit any rights You have under applicable - copyright doctrines of fair use, fair dealing, or other equivalents. - -2.7. Conditions - - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in - Section 2.1. - - -3. Responsibilities - -3.1. Distribution of Source Form - - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under the - terms of this License. You must inform recipients that the Source Code Form - of the Covered Software is governed by the terms of this License, and how - they can obtain a copy of this License. You may not attempt to alter or - restrict the recipients’ rights in the Source Code Form. - -3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - a. such Covered Software must also be made available in Source Code Form, - as described in Section 3.1, and You must inform recipients of the - Executable Form how they can obtain a copy of such Source Code Form by - reasonable means in a timely manner, at a charge no more than the cost - of distribution to the recipient; and - - b. You may distribute such Executable Form under the terms of this License, - or sublicense it under different terms, provided that the license for - the Executable Form does not attempt to limit or alter the recipients’ - rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for the - Covered Software. If the Larger Work is a combination of Covered Software - with a work governed by one or more Secondary Licenses, and the Covered - Software is not Incompatible With Secondary Licenses, this License permits - You to additionally distribute such Covered Software under the terms of - such Secondary License(s), so that the recipient of the Larger Work may, at - their option, further distribute the Covered Software under the terms of - either this License or such Secondary License(s). - -3.4. Notices - - You may not remove or alter the substance of any license notices (including - copyright notices, patent notices, disclaimers of warranty, or limitations - of liability) contained within the Source Code Form of the Covered - Software, except that You may alter any license notices to the extent - required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on behalf - of any Contributor. You must make it absolutely clear that any such - warranty, support, indemnity, or liability obligation is offered by You - alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - -4. Inability to Comply Due to Statute or Regulation - - If it is impossible for You to comply with any of the terms of this License - with respect to some or all of the Covered Software due to statute, judicial - order, or regulation then You must: (a) comply with the terms of this License - to the maximum extent possible; and (b) describe the limitations and the code - they affect. Such description must be placed in a text file included with all - distributions of the Covered Software under this License. Except to the - extent prohibited by statute or regulation, such description must be - sufficiently detailed for a recipient of ordinary skill to be able to - understand it. - -5. Termination - -5.1. The rights granted under this License will terminate automatically if You - fail to comply with any of its terms. However, if You become compliant, - then the rights granted under this License from a particular Contributor - are reinstated (a) provisionally, unless and until such Contributor - explicitly and finally terminates Your grants, and (b) on an ongoing basis, - if such Contributor fails to notify You of the non-compliance by some - reasonable means prior to 60 days after You have come back into compliance. - Moreover, Your grants from a particular Contributor are reinstated on an - ongoing basis if such Contributor notifies You of the non-compliance by - some reasonable means, this is the first time You have received notice of - non-compliance with this License from such Contributor, and You become - compliant prior to 30 days after Your receipt of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent - infringement claim (excluding declaratory judgment actions, counter-claims, - and cross-claims) alleging that a Contributor Version directly or - indirectly infringes any patent, then the rights granted to You by any and - all Contributors for the Covered Software under Section 2.1 of this License - shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user - license agreements (excluding distributors and resellers) which have been - validly granted by You or Your distributors under this License prior to - termination shall survive termination. - -6. Disclaimer of Warranty - - Covered Software is provided under this License on an “as is” basis, without - warranty of any kind, either expressed, implied, or statutory, including, - without limitation, warranties that the Covered Software is free of defects, - merchantable, fit for a particular purpose or non-infringing. The entire - risk as to the quality and performance of the Covered Software is with You. - Should any Covered Software prove defective in any respect, You (not any - Contributor) assume the cost of any necessary servicing, repair, or - correction. This disclaimer of warranty constitutes an essential part of this - License. No use of any Covered Software is authorized under this License - except under this disclaimer. - -7. Limitation of Liability - - Under no circumstances and under no legal theory, whether tort (including - negligence), contract, or otherwise, shall any Contributor, or anyone who - distributes Covered Software as permitted above, be liable to You for any - direct, indirect, special, incidental, or consequential damages of any - character including, without limitation, damages for lost profits, loss of - goodwill, work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses, even if such party shall have been - informed of the possibility of such damages. This limitation of liability - shall not apply to liability for death or personal injury resulting from such - party’s negligence to the extent applicable law prohibits such limitation. - Some jurisdictions do not allow the exclusion or limitation of incidental or - consequential damages, so this exclusion and limitation may not apply to You. - -8. Litigation - - Any litigation relating to this License may be brought only in the courts of - a jurisdiction where the defendant maintains its principal place of business - and such litigation shall be governed by laws of that jurisdiction, without - reference to its conflict-of-law provisions. Nothing in this Section shall - prevent a party’s ability to bring cross-claims or counter-claims. - -9. Miscellaneous - - This License represents the complete agreement concerning the subject matter - hereof. If any provision of this License is held to be unenforceable, such - provision shall be reformed only to the extent necessary to make it - enforceable. Any law or regulation which provides that the language of a - contract shall be construed against the drafter shall not be used to construe - this License against a Contributor. - - -10. Versions of the License - -10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - -10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version of - the License under which You originally received the Covered Software, or - under the terms of any subsequent version published by the license - steward. - -10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a modified - version of this License if you rename the license and remove any - references to the name of the license steward (except to note that such - modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses - If You choose to distribute Source Code Form that is Incompatible With - Secondary Licenses under the terms of this version of the License, the - notice described in Exhibit B of this License must be attached. - -Exhibit A - Source Code Form License Notice - - This Source Code Form is subject to the - terms of the Mozilla Public License, v. - 2.0. If a copy of the MPL was not - distributed with this file, You can - obtain one at - http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular file, then -You may include the notice in a location (such as a LICENSE file in a relevant -directory) where a recipient would be likely to look for such a notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - “Incompatible With Secondary Licenses” Notice - - This Source Code Form is “Incompatible - With Secondary Licenses”, as defined by - the Mozilla Public License, v. 2.0. diff --git a/vendor/github.com/hashicorp/go-multierror/Makefile b/vendor/github.com/hashicorp/go-multierror/Makefile deleted file mode 100644 index b97cd6e..0000000 --- a/vendor/github.com/hashicorp/go-multierror/Makefile +++ /dev/null @@ -1,31 +0,0 @@ -TEST?=./... - -default: test - -# test runs the test suite and vets the code. -test: generate - @echo "==> Running tests..." - @go list $(TEST) \ - | grep -v "/vendor/" \ - | xargs -n1 go test -timeout=60s -parallel=10 ${TESTARGS} - -# testrace runs the race checker -testrace: generate - @echo "==> Running tests (race)..." - @go list $(TEST) \ - | grep -v "/vendor/" \ - | xargs -n1 go test -timeout=60s -race ${TESTARGS} - -# updatedeps installs all the dependencies needed to run and build. -updatedeps: - @sh -c "'${CURDIR}/scripts/deps.sh' '${NAME}'" - -# generate runs `go generate` to build the dynamically generated source files. -generate: - @echo "==> Generating..." - @find . -type f -name '.DS_Store' -delete - @go list ./... \ - | grep -v "/vendor/" \ - | xargs -n1 go generate - -.PHONY: default test testrace updatedeps generate diff --git a/vendor/github.com/hashicorp/go-multierror/README.md b/vendor/github.com/hashicorp/go-multierror/README.md deleted file mode 100644 index ead5830..0000000 --- a/vendor/github.com/hashicorp/go-multierror/README.md +++ /dev/null @@ -1,97 +0,0 @@ -# go-multierror - -[![Build Status](http://img.shields.io/travis/hashicorp/go-multierror.svg?style=flat-square)][travis] -[![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs] - -[travis]: https://travis-ci.org/hashicorp/go-multierror -[godocs]: https://godoc.org/github.com/hashicorp/go-multierror - -`go-multierror` is a package for Go that provides a mechanism for -representing a list of `error` values as a single `error`. - -This allows a function in Go to return an `error` that might actually -be a list of errors. If the caller knows this, they can unwrap the -list and access the errors. If the caller doesn't know, the error -formats to a nice human-readable format. - -`go-multierror` implements the -[errwrap](https://github.com/hashicorp/errwrap) interface so that it can -be used with that library, as well. - -## Installation and Docs - -Install using `go get github.com/hashicorp/go-multierror`. - -Full documentation is available at -http://godoc.org/github.com/hashicorp/go-multierror - -## Usage - -go-multierror is easy to use and purposely built to be unobtrusive in -existing Go applications/libraries that may not be aware of it. - -**Building a list of errors** - -The `Append` function is used to create a list of errors. This function -behaves a lot like the Go built-in `append` function: it doesn't matter -if the first argument is nil, a `multierror.Error`, or any other `error`, -the function behaves as you would expect. - -```go -var result error - -if err := step1(); err != nil { - result = multierror.Append(result, err) -} -if err := step2(); err != nil { - result = multierror.Append(result, err) -} - -return result -``` - -**Customizing the formatting of the errors** - -By specifying a custom `ErrorFormat`, you can customize the format -of the `Error() string` function: - -```go -var result *multierror.Error - -// ... accumulate errors here, maybe using Append - -if result != nil { - result.ErrorFormat = func([]error) string { - return "errors!" - } -} -``` - -**Accessing the list of errors** - -`multierror.Error` implements `error` so if the caller doesn't know about -multierror, it will work just fine. But if you're aware a multierror might -be returned, you can use type switches to access the list of errors: - -```go -if err := something(); err != nil { - if merr, ok := err.(*multierror.Error); ok { - // Use merr.Errors - } -} -``` - -**Returning a multierror only if there are errors** - -If you build a `multierror.Error`, you can use the `ErrorOrNil` function -to return an `error` implementation only if there are errors to return: - -```go -var result *multierror.Error - -// ... accumulate errors here - -// Return the `error` only if errors were added to the multierror, otherwise -// return nil since there are no errors. -return result.ErrorOrNil() -``` diff --git a/vendor/github.com/hashicorp/go-multierror/append.go b/vendor/github.com/hashicorp/go-multierror/append.go deleted file mode 100644 index 775b6e7..0000000 --- a/vendor/github.com/hashicorp/go-multierror/append.go +++ /dev/null @@ -1,41 +0,0 @@ -package multierror - -// Append is a helper function that will append more errors -// onto an Error in order to create a larger multi-error. -// -// If err is not a multierror.Error, then it will be turned into -// one. If any of the errs are multierr.Error, they will be flattened -// one level into err. -func Append(err error, errs ...error) *Error { - switch err := err.(type) { - case *Error: - // Typed nils can reach here, so initialize if we are nil - if err == nil { - err = new(Error) - } - - // Go through each error and flatten - for _, e := range errs { - switch e := e.(type) { - case *Error: - if e != nil { - err.Errors = append(err.Errors, e.Errors...) - } - default: - if e != nil { - err.Errors = append(err.Errors, e) - } - } - } - - return err - default: - newErrs := make([]error, 0, len(errs)+1) - if err != nil { - newErrs = append(newErrs, err) - } - newErrs = append(newErrs, errs...) - - return Append(&Error{}, newErrs...) - } -} diff --git a/vendor/github.com/hashicorp/go-multierror/flatten.go b/vendor/github.com/hashicorp/go-multierror/flatten.go deleted file mode 100644 index aab8e9a..0000000 --- a/vendor/github.com/hashicorp/go-multierror/flatten.go +++ /dev/null @@ -1,26 +0,0 @@ -package multierror - -// Flatten flattens the given error, merging any *Errors together into -// a single *Error. -func Flatten(err error) error { - // If it isn't an *Error, just return the error as-is - if _, ok := err.(*Error); !ok { - return err - } - - // Otherwise, make the result and flatten away! - flatErr := new(Error) - flatten(err, flatErr) - return flatErr -} - -func flatten(err error, flatErr *Error) { - switch err := err.(type) { - case *Error: - for _, e := range err.Errors { - flatten(e, flatErr) - } - default: - flatErr.Errors = append(flatErr.Errors, err) - } -} diff --git a/vendor/github.com/hashicorp/go-multierror/format.go b/vendor/github.com/hashicorp/go-multierror/format.go deleted file mode 100644 index 6c7a3cc..0000000 --- a/vendor/github.com/hashicorp/go-multierror/format.go +++ /dev/null @@ -1,27 +0,0 @@ -package multierror - -import ( - "fmt" - "strings" -) - -// ErrorFormatFunc is a function callback that is called by Error to -// turn the list of errors into a string. -type ErrorFormatFunc func([]error) string - -// ListFormatFunc is a basic formatter that outputs the number of errors -// that occurred along with a bullet point list of the errors. -func ListFormatFunc(es []error) string { - if len(es) == 1 { - return fmt.Sprintf("1 error occurred:\n\n* %s", es[0]) - } - - points := make([]string, len(es)) - for i, err := range es { - points[i] = fmt.Sprintf("* %s", err) - } - - return fmt.Sprintf( - "%d errors occurred:\n\n%s", - len(es), strings.Join(points, "\n")) -} diff --git a/vendor/github.com/hashicorp/go-multierror/multierror.go b/vendor/github.com/hashicorp/go-multierror/multierror.go deleted file mode 100644 index 89b1422..0000000 --- a/vendor/github.com/hashicorp/go-multierror/multierror.go +++ /dev/null @@ -1,51 +0,0 @@ -package multierror - -import ( - "fmt" -) - -// Error is an error type to track multiple errors. This is used to -// accumulate errors in cases and return them as a single "error". -type Error struct { - Errors []error - ErrorFormat ErrorFormatFunc -} - -func (e *Error) Error() string { - fn := e.ErrorFormat - if fn == nil { - fn = ListFormatFunc - } - - return fn(e.Errors) -} - -// ErrorOrNil returns an error interface if this Error represents -// a list of errors, or returns nil if the list of errors is empty. This -// function is useful at the end of accumulation to make sure that the value -// returned represents the existence of errors. -func (e *Error) ErrorOrNil() error { - if e == nil { - return nil - } - if len(e.Errors) == 0 { - return nil - } - - return e -} - -func (e *Error) GoString() string { - return fmt.Sprintf("*%#v", *e) -} - -// WrappedErrors returns the list of errors that this Error is wrapping. -// It is an implementation of the errwrap.Wrapper interface so that -// multierror.Error can be used with that library. -// -// This method is not safe to be called concurrently and is no different -// than accessing the Errors field directly. It is implemented only to -// satisfy the errwrap.Wrapper interface. -func (e *Error) WrappedErrors() []error { - return e.Errors -} diff --git a/vendor/github.com/hashicorp/go-multierror/prefix.go b/vendor/github.com/hashicorp/go-multierror/prefix.go deleted file mode 100644 index 5c477ab..0000000 --- a/vendor/github.com/hashicorp/go-multierror/prefix.go +++ /dev/null @@ -1,37 +0,0 @@ -package multierror - -import ( - "fmt" - - "github.com/hashicorp/errwrap" -) - -// Prefix is a helper function that will prefix some text -// to the given error. If the error is a multierror.Error, then -// it will be prefixed to each wrapped error. -// -// This is useful to use when appending multiple multierrors -// together in order to give better scoping. -func Prefix(err error, prefix string) error { - if err == nil { - return nil - } - - format := fmt.Sprintf("%s {{err}}", prefix) - switch err := err.(type) { - case *Error: - // Typed nils can reach here, so initialize if we are nil - if err == nil { - err = new(Error) - } - - // Wrap each of the errors - for i, e := range err.Errors { - err.Errors[i] = errwrap.Wrapf(format, e) - } - - return err - default: - return errwrap.Wrapf(format, err) - } -} diff --git a/vendor/github.com/mmcloughlin/geohash/.appveyor.yml b/vendor/github.com/mmcloughlin/geohash/.appveyor.yml deleted file mode 100644 index aecdaf0..0000000 --- a/vendor/github.com/mmcloughlin/geohash/.appveyor.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: "{build}" - -clone_folder: c:\gopath\src\github.com\mmcloughlin\geohash - -environment: - GOPATH: c:\gopath - -install: - - echo %PATH% - - echo %GOPATH% - - go version - - go env - -build_script: - - go test -v diff --git a/vendor/github.com/mmcloughlin/geohash/.gitignore b/vendor/github.com/mmcloughlin/geohash/.gitignore deleted file mode 100644 index 13e3457..0000000 --- a/vendor/github.com/mmcloughlin/geohash/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -# Compiled Object files, Static and Dynamic libs (Shared Objects) -*.o -*.a -*.so - -# Folders -_obj -_test - -# Architecture specific extensions/prefixes -*.[568vq] -[568vq].out - -*.cgo1.go -*.cgo2.c -_cgo_defun.c -_cgo_gotypes.go -_cgo_export.* - -_testmain.go - -*.exe -*.test -*.prof - -coverage.out diff --git a/vendor/github.com/mmcloughlin/geohash/LICENSE b/vendor/github.com/mmcloughlin/geohash/LICENSE deleted file mode 100644 index c0190c9..0000000 --- a/vendor/github.com/mmcloughlin/geohash/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Michael McLoughlin - -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/vendor/github.com/mmcloughlin/geohash/README.md b/vendor/github.com/mmcloughlin/geohash/README.md deleted file mode 100644 index 0a34e3e..0000000 --- a/vendor/github.com/mmcloughlin/geohash/README.md +++ /dev/null @@ -1,214 +0,0 @@ -# geohash - -Go [geohash](https://en.wikipedia.org/wiki/Geohash) library offering encoding -and decoding for string and integer geohashes. - -[![GoDoc Reference](http://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square)](http://godoc.org/github.com/mmcloughlin/geohash) -[![Build status](https://img.shields.io/travis/mmcloughlin/geohash.svg?style=flat-square)](https://travis-ci.org/mmcloughlin/geohash) -[![Coverage](https://img.shields.io/coveralls/mmcloughlin/geohash.svg?style=flat-square)](https://coveralls.io/r/mmcloughlin/geohash) -[![Go Report Card](https://goreportcard.com/badge/github.com/mmcloughlin/geohash?style=flat-square)](https://goreportcard.com/report/github.com/mmcloughlin/geohash) - -## Install - -Fetch the package with - -``` -go get github.com/mmcloughlin/geohash -``` - -And import it into your programs with - -```go -import "github.com/mmcloughlin/geohash" -``` - -## Usage - -#### func Decode - -```go -func Decode(hash string) (lat, lng float64) -``` -Decode the string geohash to a (lat, lng) point. - -#### func DecodeCenter - -```go -func DecodeCenter(hash string) (lat, lng float64) -``` -DecodeCenter decodes the string geohash to the central point of the bounding -box. - -#### func DecodeInt - -```go -func DecodeInt(hash uint64) (lat, lng float64) -``` -DecodeInt decodes the provided 64-bit integer geohash to a (lat, lng) point. - -#### func DecodeIntWithPrecision - -```go -func DecodeIntWithPrecision(hash uint64, bits uint) (lat, lng float64) -``` -DecodeIntWithPrecision decodes the provided integer geohash with bits of -precision to a (lat, lng) point. - -#### func Encode - -```go -func Encode(lat, lng float64) string -``` -Encode the point (lat, lng) as a string geohash with the standard 12 characters -of precision. - -#### func EncodeInt - -```go -func EncodeInt(lat, lng float64) uint64 -``` -EncodeInt encodes the point (lat, lng) to a 64-bit integer geohash. - -#### func EncodeIntWithPrecision - -```go -func EncodeIntWithPrecision(lat, lng float64, bits uint) uint64 -``` -EncodeIntWithPrecision encodes the point (lat, lng) to an integer with the -specified number of bits. - -#### func EncodeWithPrecision - -```go -func EncodeWithPrecision(lat, lng float64, chars uint) string -``` -EncodeWithPrecision encodes the point (lat, lng) as a string geohash with the -specified number of characters of precision (max 12). - -#### func Neighbor - -```go -func Neighbor(hash string, direction Direction) string -``` -Neighbor returns a geohash string that corresponds to the provided geohash's -neighbor in the provided direction - -#### func NeighborInt - -```go -func NeighborInt(hash uint64, direction Direction) uint64 -``` -NeighborInt returns a uint64 that corresponds to the provided hash's neighbor in -the provided direction at 64-bit precision. - -#### func NeighborIntWithPrecision - -```go -func NeighborIntWithPrecision(hash uint64, bits uint, direction Direction) uint64 -``` -NeighborIntWithPrecision returns a uint64s that corresponds to the provided -hash's neighbor in the provided direction at the given precision. - -#### func Neighbors - -```go -func Neighbors(hash string) []string -``` -Neighbors returns a slice of geohash strings that correspond to the provided -geohash's neighbors. - -#### func NeighborsInt - -```go -func NeighborsInt(hash uint64) []uint64 -``` -NeighborsInt returns a slice of uint64s that correspond to the provided hash's -neighbors at 64-bit precision. - -#### func NeighborsIntWithPrecision - -```go -func NeighborsIntWithPrecision(hash uint64, bits uint) []uint64 -``` -NeighborsIntWithPrecision returns a slice of uint64s that correspond to the -provided hash's neighbors at the given precision. - -#### type Box - -```go -type Box struct { - MinLat float64 - MaxLat float64 - MinLng float64 - MaxLng float64 -} -``` - -Box represents a rectangle in latitude/longitude space. - -#### func BoundingBox - -```go -func BoundingBox(hash string) Box -``` -BoundingBox returns the region encoded by the given string geohash. - -#### func BoundingBoxInt - -```go -func BoundingBoxInt(hash uint64) Box -``` -BoundingBoxInt returns the region encoded by the given 64-bit integer geohash. - -#### func BoundingBoxIntWithPrecision - -```go -func BoundingBoxIntWithPrecision(hash uint64, bits uint) Box -``` -BoundingBoxIntWithPrecision returns the region encoded by the integer geohash -with the specified precision. - -#### func (Box) Center - -```go -func (b Box) Center() (lat, lng float64) -``` -Center returns the center of the box. - -#### func (Box) Contains - -```go -func (b Box) Contains(lat, lng float64) bool -``` -Contains decides whether (lat, lng) is contained in the box. The containment -test is inclusive of the edges and corners. - -#### func (Box) Round - -```go -func (b Box) Round() (lat, lng float64) -``` -Round returns a point inside the box, making an effort to round to minimal -precision. - -#### type Direction - -```go -type Direction int -``` - -Direction represents directions in the latitute/longitude space. - -```go -const ( - North Direction = iota - NorthEast - East - SouthEast - South - SouthWest - West - NorthWest -) -``` -Cardinal and intercardinal directions diff --git a/vendor/github.com/mmcloughlin/geohash/README.tmpl b/vendor/github.com/mmcloughlin/geohash/README.tmpl deleted file mode 100644 index 6f0fe4b..0000000 --- a/vendor/github.com/mmcloughlin/geohash/README.tmpl +++ /dev/null @@ -1,25 +0,0 @@ -# geohash - -Go [geohash](https://en.wikipedia.org/wiki/Geohash) library offering encoding -and decoding for string and integer geohashes. - -[![GoDoc Reference](http://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square)](http://godoc.org/github.com/mmcloughlin/geohash) -[![Build status](https://img.shields.io/travis/mmcloughlin/geohash.svg?style=flat-square)](https://travis-ci.org/mmcloughlin/geohash) -[![Coverage](https://img.shields.io/coveralls/mmcloughlin/geohash.svg?style=flat-square)](https://coveralls.io/r/mmcloughlin/geohash) -[![Go Report Card](https://goreportcard.com/badge/github.com/mmcloughlin/geohash?style=flat-square)](https://goreportcard.com/report/github.com/mmcloughlin/geohash) - -## Install - -Fetch the package with - -``` -go get {{ .ImportPath }} -``` - -And import it into your programs with - -```go -import "{{ .ImportPath }}" -``` - -{{ .EmitUsage }} diff --git a/vendor/github.com/mmcloughlin/geohash/asm_x86.s b/vendor/github.com/mmcloughlin/geohash/asm_x86.s deleted file mode 100644 index 0d2d80c..0000000 --- a/vendor/github.com/mmcloughlin/geohash/asm_x86.s +++ /dev/null @@ -1,56 +0,0 @@ -// +build amd64,go1.6 - -#include "textflag.h" - -// func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) -TEXT ·cpuid(SB), NOSPLIT, $0-24 - MOVL eaxArg+0(FP), AX - MOVL ecxArg+4(FP), CX - CPUID - MOVL AX, eax+8(FP) - MOVL BX, ebx+12(FP) - MOVL CX, ecx+16(FP) - MOVL DX, edx+20(FP) - RET - -// func EncodeInt(lat, lng float64) uint64 -TEXT ·EncodeInt(SB), NOSPLIT, $0 - CMPB ·useAsm(SB), $1 - JNE fallback - -#define LATF X0 -#define LATI R8 -#define LNGF X1 -#define LNGI R9 -#define TEMP R10 -#define GHSH R11 -#define MASK BX - - MOVSD lat+0(FP), LATF - MOVSD lng+8(FP), LNGF - - MOVQ $0x5555555555555555, MASK - - MULSD $(0.005555555555555556), LATF - ADDSD $(1.5), LATF - - MULSD $(0.002777777777777778), LNGF - ADDSD $(1.5), LNGF - - MOVQ LNGF, LNGI - SHRQ $20, LNGI - - MOVQ LATF, LATI - SHRQ $20, LATI - PDEPQ MASK, LATI, GHSH - - PDEPQ MASK, LNGI, TEMP - - SHLQ $1, TEMP - XORQ TEMP, GHSH - - MOVQ GHSH, ret+16(FP) - RET - -fallback: - JMP ·encodeInt(SB) diff --git a/vendor/github.com/mmcloughlin/geohash/base32.go b/vendor/github.com/mmcloughlin/geohash/base32.go deleted file mode 100644 index 916b272..0000000 --- a/vendor/github.com/mmcloughlin/geohash/base32.go +++ /dev/null @@ -1,44 +0,0 @@ -package geohash - -// encoding encapsulates an encoding defined by a given base32 alphabet. -type encoding struct { - encode string - decode [256]byte -} - -// newEncoding constructs a new encoding defined by the given alphabet, -// which must be a 32-byte string. -func newEncoding(encoder string) *encoding { - e := new(encoding) - e.encode = encoder - for i := 0; i < len(e.decode); i++ { - e.decode[i] = 0xff - } - for i := 0; i < len(encoder); i++ { - e.decode[encoder[i]] = byte(i) - } - return e -} - -// Decode string into bits of a 64-bit word. The string s may be at most 12 -// characters. -func (e *encoding) Decode(s string) uint64 { - x := uint64(0) - for i := 0; i < len(s); i++ { - x = (x << 5) | uint64(e.decode[s[i]]) - } - return x -} - -// Encode bits of 64-bit word into a string. -func (e *encoding) Encode(x uint64) string { - b := [12]byte{} - for i := 0; i < 12; i++ { - b[11-i] = e.encode[x&0x1f] - x >>= 5 - } - return string(b[:]) -} - -// Base32Encoding with the Geohash alphabet. -var base32encoding = newEncoding("0123456789bcdefghjkmnpqrstuvwxyz") diff --git a/vendor/github.com/mmcloughlin/geohash/geohash.go b/vendor/github.com/mmcloughlin/geohash/geohash.go deleted file mode 100644 index 8563304..0000000 --- a/vendor/github.com/mmcloughlin/geohash/geohash.go +++ /dev/null @@ -1,292 +0,0 @@ -// Package geohash provides encoding and decoding of string and integer -// geohashes. -package geohash - -import ( - "math" -) - -// Direction represents directions in the latitute/longitude space. -type Direction int - -// Cardinal and intercardinal directions -const ( - North Direction = iota - NorthEast - East - SouthEast - South - SouthWest - West - NorthWest -) - -// Encode the point (lat, lng) as a string geohash with the standard 12 -// characters of precision. -func Encode(lat, lng float64) string { - return EncodeWithPrecision(lat, lng, 12) -} - -// EncodeWithPrecision encodes the point (lat, lng) as a string geohash with -// the specified number of characters of precision (max 12). -func EncodeWithPrecision(lat, lng float64, chars uint) string { - bits := 5 * chars - inthash := EncodeIntWithPrecision(lat, lng, bits) - enc := base32encoding.Encode(inthash) - return enc[12-chars:] -} - -// EncodeInt encodes the point (lat, lng) to a 64-bit integer geohash. -func EncodeInt(lat, lng float64) uint64 - -// encodeInt provides a Go implementation of integer geohash. This is the -// default implementation of EncodeInt, but optimized versions are provided -// for certain architectures. -func encodeInt(lat, lng float64) uint64 { - latInt := encodeRange(lat, 90) - lngInt := encodeRange(lng, 180) - return interleave(latInt, lngInt) -} - -// EncodeIntWithPrecision encodes the point (lat, lng) to an integer with the -// specified number of bits. -func EncodeIntWithPrecision(lat, lng float64, bits uint) uint64 { - hash := EncodeInt(lat, lng) - return hash >> (64 - bits) -} - -// Box represents a rectangle in latitude/longitude space. -type Box struct { - MinLat float64 - MaxLat float64 - MinLng float64 - MaxLng float64 -} - -// Center returns the center of the box. -func (b Box) Center() (lat, lng float64) { - lat = (b.MinLat + b.MaxLat) / 2.0 - lng = (b.MinLng + b.MaxLng) / 2.0 - return -} - -// Contains decides whether (lat, lng) is contained in the box. The -// containment test is inclusive of the edges and corners. -func (b Box) Contains(lat, lng float64) bool { - return (b.MinLat <= lat && lat <= b.MaxLat && - b.MinLng <= lng && lng <= b.MaxLng) -} - -// minDecimalPlaces returns the minimum number of decimal places such that -// there must exist an number with that many places within any range of width -// r. This is intended for returning minimal precision coordinates inside a -// box. -func maxDecimalPower(r float64) float64 { - m := int(math.Floor(math.Log10(r))) - return math.Pow10(m) -} - -// Round returns a point inside the box, making an effort to round to minimal -// precision. -func (b Box) Round() (lat, lng float64) { - x := maxDecimalPower(b.MaxLat - b.MinLat) - lat = math.Ceil(b.MinLat/x) * x - x = maxDecimalPower(b.MaxLng - b.MinLng) - lng = math.Ceil(b.MinLng/x) * x - return -} - -// errorWithPrecision returns the error range in latitude and longitude for in -// integer geohash with bits of precision. -func errorWithPrecision(bits uint) (latErr, lngErr float64) { - b := int(bits) - latBits := b / 2 - lngBits := b - latBits - latErr = math.Ldexp(180.0, -latBits) - lngErr = math.Ldexp(360.0, -lngBits) - return -} - -// BoundingBox returns the region encoded by the given string geohash. -func BoundingBox(hash string) Box { - bits := uint(5 * len(hash)) - inthash := base32encoding.Decode(hash) - return BoundingBoxIntWithPrecision(inthash, bits) -} - -// BoundingBoxIntWithPrecision returns the region encoded by the integer -// geohash with the specified precision. -func BoundingBoxIntWithPrecision(hash uint64, bits uint) Box { - fullHash := hash << (64 - bits) - latInt, lngInt := deinterleave(fullHash) - lat := decodeRange(latInt, 90) - lng := decodeRange(lngInt, 180) - latErr, lngErr := errorWithPrecision(bits) - return Box{ - MinLat: lat, - MaxLat: lat + latErr, - MinLng: lng, - MaxLng: lng + lngErr, - } -} - -// BoundingBoxInt returns the region encoded by the given 64-bit integer -// geohash. -func BoundingBoxInt(hash uint64) Box { - return BoundingBoxIntWithPrecision(hash, 64) -} - -// Decode the string geohash to a (lat, lng) point. -func Decode(hash string) (lat, lng float64) { - box := BoundingBox(hash) - return box.Round() -} - -// DecodeCenter decodes the string geohash to the central point of the bounding box. -func DecodeCenter(hash string) (lat, lng float64) { - box := BoundingBox(hash) - return box.Center() -} - -// DecodeIntWithPrecision decodes the provided integer geohash with bits of -// precision to a (lat, lng) point. -func DecodeIntWithPrecision(hash uint64, bits uint) (lat, lng float64) { - box := BoundingBoxIntWithPrecision(hash, bits) - return box.Round() -} - -// DecodeInt decodes the provided 64-bit integer geohash to a (lat, lng) point. -func DecodeInt(hash uint64) (lat, lng float64) { - return DecodeIntWithPrecision(hash, 64) -} - -// Neighbors returns a slice of geohash strings that correspond to the provided -// geohash's neighbors. -func Neighbors(hash string) []string { - box := BoundingBox(hash) - lat, lng := box.Center() - latDelta := box.MaxLat - box.MinLat - lngDelta := box.MaxLng - box.MinLng - precision := uint(len(hash)) - return []string{ - // N - EncodeWithPrecision(lat+latDelta, lng, precision), - // NE, - EncodeWithPrecision(lat+latDelta, lng+lngDelta, precision), - // E, - EncodeWithPrecision(lat, lng+lngDelta, precision), - // SE, - EncodeWithPrecision(lat-latDelta, lng+lngDelta, precision), - // S, - EncodeWithPrecision(lat-latDelta, lng, precision), - // SW, - EncodeWithPrecision(lat-latDelta, lng-lngDelta, precision), - // W, - EncodeWithPrecision(lat, lng-lngDelta, precision), - // NW - EncodeWithPrecision(lat+latDelta, lng-lngDelta, precision), - } -} - -// NeighborsInt returns a slice of uint64s that correspond to the provided hash's -// neighbors at 64-bit precision. -func NeighborsInt(hash uint64) []uint64 { - return NeighborsIntWithPrecision(hash, 64) -} - -// NeighborsIntWithPrecision returns a slice of uint64s that correspond to the -// provided hash's neighbors at the given precision. -func NeighborsIntWithPrecision(hash uint64, bits uint) []uint64 { - box := BoundingBoxIntWithPrecision(hash, bits) - lat, lng := box.Center() - latDelta := box.MaxLat - box.MinLat - lngDelta := box.MaxLng - box.MinLng - return []uint64{ - // N - EncodeIntWithPrecision(lat+latDelta, lng, bits), - // NE, - EncodeIntWithPrecision(lat+latDelta, lng+lngDelta, bits), - // E, - EncodeIntWithPrecision(lat, lng+lngDelta, bits), - // SE, - EncodeIntWithPrecision(lat-latDelta, lng+lngDelta, bits), - // S, - EncodeIntWithPrecision(lat-latDelta, lng, bits), - // SW, - EncodeIntWithPrecision(lat-latDelta, lng-lngDelta, bits), - // W, - EncodeIntWithPrecision(lat, lng-lngDelta, bits), - // NW - EncodeIntWithPrecision(lat+latDelta, lng-lngDelta, bits), - } -} - -// Neighbor returns a geohash string that corresponds to the provided -// geohash's neighbor in the provided direction -func Neighbor(hash string, direction Direction) string { - return Neighbors(hash)[direction] -} - -// NeighborInt returns a uint64 that corresponds to the provided hash's -// neighbor in the provided direction at 64-bit precision. -func NeighborInt(hash uint64, direction Direction) uint64 { - return NeighborsIntWithPrecision(hash, 64)[direction] -} - -// NeighborIntWithPrecision returns a uint64s that corresponds to the -// provided hash's neighbor in the provided direction at the given precision. -func NeighborIntWithPrecision(hash uint64, bits uint, direction Direction) uint64 { - return NeighborsIntWithPrecision(hash, bits)[direction] -} - -// precalculated for performance -var exp232 = math.Exp2(32) - -// Encode the position of x within the range -r to +r as a 32-bit integer. -func encodeRange(x, r float64) uint32 { - p := (x + r) / (2 * r) - return uint32(p * exp232) -} - -// Decode the 32-bit range encoding X back to a value in the range -r to +r. -func decodeRange(X uint32, r float64) float64 { - p := float64(X) / exp232 - x := 2*r*p - r - return x -} - -// Spread out the 32 bits of x into 64 bits, where the bits of x occupy even -// bit positions. -func spread(x uint32) uint64 { - X := uint64(x) - X = (X | (X << 16)) & 0x0000ffff0000ffff - X = (X | (X << 8)) & 0x00ff00ff00ff00ff - X = (X | (X << 4)) & 0x0f0f0f0f0f0f0f0f - X = (X | (X << 2)) & 0x3333333333333333 - X = (X | (X << 1)) & 0x5555555555555555 - return X -} - -// Interleave the bits of x and y. In the result, x and y occupy even and odd -// bitlevels, respectively. -func interleave(x, y uint32) uint64 { - return spread(x) | (spread(y) << 1) -} - -// Squash the even bitlevels of X into a 32-bit word. Odd bitlevels of X are -// ignored, and may take any value. -func squash(X uint64) uint32 { - X &= 0x5555555555555555 - X = (X | (X >> 1)) & 0x3333333333333333 - X = (X | (X >> 2)) & 0x0f0f0f0f0f0f0f0f - X = (X | (X >> 4)) & 0x00ff00ff00ff00ff - X = (X | (X >> 8)) & 0x0000ffff0000ffff - X = (X | (X >> 16)) & 0x00000000ffffffff - return uint32(X) -} - -// Deinterleave the bits of X into 32-bit words containing the even and odd -// bitlevels of X, respectively. -func deinterleave(X uint64) (uint32, uint32) { - return squash(X), squash(X >> 1) -} diff --git a/vendor/github.com/mmcloughlin/geohash/geohash_x86.go b/vendor/github.com/mmcloughlin/geohash/geohash_x86.go deleted file mode 100644 index 68cfb18..0000000 --- a/vendor/github.com/mmcloughlin/geohash/geohash_x86.go +++ /dev/null @@ -1,24 +0,0 @@ -// +build amd64,go1.6 - -package geohash - -// useAsm flag determines whether the assembly version of EncodeInt will be -// used. By Default we fall back to encodeInt. -var useAsm bool - -// cpuid executes the CPUID instruction to obtain processor identification and -// feature information. -func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) - -// hasBMI2 returns whether the CPU supports Bit Manipulation Instruction Set -// 2. -func hasBMI2() bool { - _, ebx, _, _ := cpuid(7, 0) - return ebx&(1<<8) != 0 -} - -// init determines whether to use assembly version by performing CPU feature -// check. -func init() { - useAsm = hasBMI2() -} diff --git a/vendor/github.com/mmcloughlin/geohash/go.mod b/vendor/github.com/mmcloughlin/geohash/go.mod deleted file mode 100644 index 2a5f5c2..0000000 --- a/vendor/github.com/mmcloughlin/geohash/go.mod +++ /dev/null @@ -1 +0,0 @@ -module github.com/mmcloughlin/geohash diff --git a/vendor/github.com/mmcloughlin/geohash/stubs.s b/vendor/github.com/mmcloughlin/geohash/stubs.s deleted file mode 100644 index 97c046c..0000000 --- a/vendor/github.com/mmcloughlin/geohash/stubs.s +++ /dev/null @@ -1,7 +0,0 @@ -// +build !amd64 !go1.6 - -// Define NOSPLIT ourselves since "textflag.h" is missing in old Go versions. -#define NOSPLIT 4 - -TEXT ·EncodeInt(SB), NOSPLIT, $0 - JMP ·encodeInt(SB) diff --git a/vendor/github.com/skelterjohn/geom/.gitignore b/vendor/github.com/skelterjohn/geom/.gitignore deleted file mode 100644 index 4191620..0000000 --- a/vendor/github.com/skelterjohn/geom/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -*~ -_obj -*.6 diff --git a/vendor/github.com/skelterjohn/geom/LICENSE b/vendor/github.com/skelterjohn/geom/LICENSE deleted file mode 100644 index fa2350d..0000000 --- a/vendor/github.com/skelterjohn/geom/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright 2012 John Asmuth. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY JOHN ASMUTH ``AS IS'' AND ANY EXPRESS OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT -SHALL JOHN ASMUTH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -The views and conclusions contained in the software and documentation are those -of the authors and should not be interpreted as representing official policies, -either expressed or implied, of John Asmuth. diff --git a/vendor/github.com/skelterjohn/geom/README b/vendor/github.com/skelterjohn/geom/README deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/github.com/skelterjohn/geom/coord.go b/vendor/github.com/skelterjohn/geom/coord.go deleted file mode 100644 index 4663964..0000000 --- a/vendor/github.com/skelterjohn/geom/coord.go +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright 2012 The geom Authors. All rights reserved. -// Use of this source code is governed by a license that -// can be found in the LICENSE file. - -package geom - -import ( - "math" -) - -type Coord struct { - X, Y float64 -} - -func (p *Coord) Hashcode() (hash uint64) { - x, y := uint64(p.X), uint64(p.Y) - hash = x + y - return -} - -func (p *Coord) Equals(oi interface{}) (equals bool) { - o, equals := oi.(*Coord) - if !equals { - var op Coord - op, equals = oi.(Coord) - equals = equals && p.EqualsCoord(op) - return - } - equals = p.EqualsCoord(*o) - return -} - -func (p *Coord) Translate(offset Coord) { - *p = p.Plus(offset) -} - -func (p *Coord) Rotate(rad float64) { - p.X, p.Y = - p.X*math.Cos(rad)-p.Y*math.Sin(rad), - p.X*math.Sin(rad)+p.Y*math.Cos(rad) -} - -func (p *Coord) RotateLeft() { - p.X, p.Y = -p.Y, p.X -} - -func (p *Coord) RotateRight() { - p.X, p.Y = p.Y, -p.X -} - -func (p Coord) Unit() (u Coord) { - m := p.Magnitude() - u.X = p.X / m - u.Y = p.Y / m - return -} - -func (p *Coord) Scale(xfactor, yfactor float64) { - p.X *= xfactor - p.Y *= yfactor -} - -func (p Coord) EqualsCoord(q Coord) bool { - return p.X == q.X && p.Y == q.Y -} - -func (p Coord) DistanceFrom(q Coord) (d float64) { - return p.Minus(q).Magnitude() -} - -func (p Coord) DistanceFromSquared(q Coord) (ds float64) { - return p.Minus(q).MagnitudeSquared() -} - -func (p Coord) Magnitude() (m float64) { - m = math.Sqrt(p.MagnitudeSquared()) - return -} - -func (p Coord) MagnitudeSquared() (ms float64) { - ms = p.X*p.X + p.Y*p.Y - return -} - -func (p Coord) Minus(q Coord) (r Coord) { - r.X = p.X - q.X - r.Y = p.Y - q.Y - return -} - -func (p Coord) Plus(q Coord) (r Coord) { - r.X = p.X + q.X - r.Y = p.Y + q.Y - return -} - -func (p Coord) Times(s float64) (r Coord) { - r.X = p.X * s - r.Y = p.Y * s - return -} - -func (p Coord) QuadPP(q Coord) bool { - return q.X >= p.X && q.Y >= p.Y -} - -func (p Coord) QuadPM(q Coord) bool { - return q.X >= p.X && q.Y <= p.Y -} - -func (p Coord) QuadMP(q Coord) bool { - return q.X <= p.X && q.Y >= p.Y -} - -func (p Coord) QuadMM(q Coord) bool { - return q.X <= p.X && q.Y <= p.Y -} - -func DotProduct(p, q Coord) (r float64) { - r = p.X*q.X + p.Y*q.Y - return -} - -func CrossProduct(p, q Coord) (z float64) { - z = p.X*q.Y - p.Y*q.X - return -} - -func VectorAngle(X, Y Coord) (r float64) { - XdotY := DotProduct(X, Y) - mXmY := X.Magnitude() * Y.Magnitude() - r = math.Acos(XdotY / mXmY) - z := CrossProduct(X, Y) - if z < 0 { - r *= -1 - } - return -} - -func VertexAngle(A, B, C Coord) (r float64) { - X := A.Minus(B) - Y := C.Minus(B) - r = VectorAngle(X, Y) - if r < 0 { - r *= -1 - } - return -} - -func CoordChan(points []Coord) (ch <-chan Coord) { - tch := make(chan Coord, len(points)) - go func(points []Coord, ch chan<- Coord) { - for _, p := range points { - ch <- p - } - close(ch) - }(points, tch) - ch = tch - return -} diff --git a/vendor/github.com/skelterjohn/geom/debug.go b/vendor/github.com/skelterjohn/geom/debug.go deleted file mode 100644 index 5ee8543..0000000 --- a/vendor/github.com/skelterjohn/geom/debug.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2012 The geom Authors. All rights reserved. -// Use of this source code is governed by a license that -// can be found in the LICENSE file. - -package geom - -import "fmt" - -var Debug = false - -func dbg(format string, args ...interface{}) { - if Debug { - fmt.Printf(format+"\n", args...) - } -} diff --git a/vendor/github.com/skelterjohn/geom/geom.go b/vendor/github.com/skelterjohn/geom/geom.go deleted file mode 100644 index d8ae3e7..0000000 --- a/vendor/github.com/skelterjohn/geom/geom.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2012 The geom Authors. All rights reserved. -// Use of this source code is governed by a license that -// can be found in the LICENSE file. - -package geom - -type Bounded interface { - Bounds() (bounds Rect) -} - -type Transformable interface { - Translate(offset Coord) - Rotate(rad float64) - Scale(xfactor, yfactor float64) -} diff --git a/vendor/github.com/skelterjohn/geom/line.go b/vendor/github.com/skelterjohn/geom/line.go deleted file mode 100644 index dfa59cd..0000000 --- a/vendor/github.com/skelterjohn/geom/line.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2012 The geom Authors. All rights reserved. -// Use of this source code is governed by a license that -// can be found in the LICENSE file. - -package geom - -/* -A line that goes through Intersection and has a normal Normal. -*/ -type Line struct { - Intersection Coord - Normal Coord -} - -func LineIntersection(l1, l2 Line) (p Coord) { - b1 := l1.Normal.Unit() - b1.RotateRight() - unum := (l2.Normal.X*l2.Intersection.X + l2.Normal.Y*l2.Intersection.Y) - uden := (l2.Normal.X*b1.X + l2.Normal.Y*b1.Y) - u := unum / uden - p = l1.Intersection.Plus(b1.Times(u)) - return -} diff --git a/vendor/github.com/skelterjohn/geom/path.go b/vendor/github.com/skelterjohn/geom/path.go deleted file mode 100644 index e10e02d..0000000 --- a/vendor/github.com/skelterjohn/geom/path.go +++ /dev/null @@ -1,134 +0,0 @@ -// Copyright 2012 The geom Authors. All rights reserved. -// Use of this source code is governed by a license that -// can be found in the LICENSE file. - -package geom - -import ( - "math" -) - -type Path struct { - vertices []Coord - bounds Rect -} - -func (p *Path) Translate(offset Coord) { - p.bounds.Translate(offset) - for i := range p.vertices { - p.vertices[i].Translate(offset) - } -} - -func (p *Path) Rotate(rad float64) { - for i := range p.vertices { - p.vertices[i].Rotate(rad) - } - p.bounds = Rect{p.vertices[0], p.vertices[0]} - p.bounds.ExpandToContain(CoordChan(p.vertices[1:])) -} - -func (p *Path) Scale(xf, yf float64) { - - for i := range p.vertices { - p.vertices[i].Scale(xf, yf) - } - p.bounds.Scale(xf, yf) -} - -func (p *Path) Clone() (op *Path) { - op = &Path{} - op.bounds = p.bounds - op.vertices = append([]Coord{}, p.vertices...) - return -} - -//uncomment to check interface fulfillment -//var _ Bounded = &Path{} - -func (p *Path) Equals(oi interface{}) bool { - o, ok := oi.(*Path) - if !ok { - return false - } - - if len(p.vertices) != len(o.vertices) { - return false - } - - for i := range p.vertices { - if !p.vertices[i].EqualsCoord(o.vertices[i]) { - return false - } - } - - return true -} - -func (p *Path) Register(op *Path) (offset Coord, match bool) { - offset = p.bounds.Min.Minus(op.bounds.Min) - if len(p.vertices) != len(op.vertices) { - dbg("registure failure: wrong counts") - return // with match = false - } - for i := range p.vertices { - if !p.vertices[i].EqualsCoord(op.vertices[i].Plus(offset)) { - dbg("register failure: v1=%v v2=%v offset=%v", p.vertices[i], op.vertices[i], offset) - return // with match = false - } - } - match = true - return -} - -func (p *Path) Length() int { - return len(p.vertices) -} - -func (p *Path) AddVertex(v Coord) { - if len(p.vertices) == 0 { - p.bounds = Rect{ - Min: v, - Max: v, - } - } else { - p.bounds.ExpandToContainCoord(v) - } - p.vertices = append(p.vertices, v) -} - -func (p *Path) InsertVertexAfter(v Coord, index int) { - p.vertices = append(p.vertices, v) - copy(p.vertices[index+1:], p.vertices[index:len(p.vertices)-1]) - p.vertices[index] = v -} - -func (p *Path) Bounds() (bounds *Rect) { - return &p.bounds -} - -func (p *Path) Vertices() (v []Coord) { - v = p.vertices - return -} - -func (me *Path) Error(other *Path) (offset Coord, error float64) { - - meCenter := me.bounds.Center() - oCenter := other.bounds.Center() - - offset = meCenter.Minus(oCenter) - if len(me.vertices) != len(other.vertices) { - error = math.Inf(1) - return - } - - for i, mv := range me.vertices { - ov := other.vertices[i] - offsetMe := mv.Minus(meCenter) - offsetOther := ov.Minus(oCenter) - error += offsetMe.DistanceFrom(offsetOther) - } - - return -} diff --git a/vendor/github.com/skelterjohn/geom/poly.go b/vendor/github.com/skelterjohn/geom/poly.go deleted file mode 100644 index 29b3b0a..0000000 --- a/vendor/github.com/skelterjohn/geom/poly.go +++ /dev/null @@ -1,159 +0,0 @@ -// Copyright 2012 The geom Authors. All rights reserved. -// Use of this source code is governed by a license that -// can be found in the LICENSE file. - -package geom - -import ( - "math" -) - -type Polygon struct { - Path -} - -func wrapIndex(index, length int) (i int) { - i = index % length - if i < 0 { - i = length + i - } - return -} - -func (p *Polygon) Clone() (op *Polygon) { - op = &Polygon{*p.Path.Clone()} - return -} - -func (p *Polygon) Equals(oi interface{}) bool { - o, ok := oi.(*Polygon) - if !ok { - return false - } - return (&p.Path).Equals(&o.Path) -} - -func (p *Polygon) Register(op *Polygon) (offset Coord, match bool) { - offset, match = p.Path.Register(&op.Path) - return -} - -func (me *Polygon) Vertex(index int) (v Coord) { - v = me.vertices[wrapIndex(index, len(me.vertices))] - return -} - -func (me *Polygon) Segment(index int) (s *Segment) { - s = &Segment{me.Vertex(index), me.Vertex(index + 1)} - return -} - -func (me *Polygon) VertexAngle(index int) (r float64) { - a := me.Vertex(index - 1) - b := me.Vertex(index) - c := me.Vertex(index + 1) - r = VertexAngle(a, b, c) - return -} - -func (me *Polygon) WindingOrder() (winding float64) { - for i := 0; i < len(me.vertices); i++ { - winding += me.VertexAngle(i) - } - return -} - -func (me *Polygon) ContainsCoord(p Coord) bool { - fakeSegment := &Segment{p, Coord{p.X, p.Y + 1}} - - above := 0 - for i := 0; i < me.Length(); i++ { - s := me.Segment(i) - uh, uv := s.IntersectParameters(fakeSegment) - if uh < 0 || uh >= 1 { - continue - } - if uv > 0 { - above++ - } - } - return above%2 == 1 -} - -//bisect a polygon by joining vertices i and j -func (me *Polygon) Bisect(i, j int) (p1, p2 *Polygon) { - i = wrapIndex(i, len(me.vertices)) - j = wrapIndex(j, len(me.vertices)) - - //build the first one, starting at i and ending at j - p1 = &Polygon{} - for c := i; c != wrapIndex(j+1, len(me.vertices)); c = wrapIndex(c+1, len(me.vertices)) { - p1.AddVertex(me.Vertex(c)) - } - - //build the second one, starting at j and ending at i - p2 = &Polygon{} - for c := j; c != wrapIndex(i+1, len(me.vertices)); c = wrapIndex(c+1, len(me.vertices)) { - p2.AddVertex(me.Vertex(c)) - } - - return -} - -func (me *Polygon) Error(other *Polygon) (offset Coord, error float64) { - return me.Path.Error(&other.Path) -} - -func (me *Polygon) Triangles() (tris []Triangle, ok bool) { - dbg("%v.Triangles()", me) - - if me.Length() == 3 { - dbg("already a triangle") - tris = []Triangle{Triangle{me.Vertex(0), me.Vertex(1), me.Vertex(2)}} - ok = true - return - } - - for i := 0; i < me.Length(); i++ { - iv := me.Vertex(i) - v2: - for j := i + 2; j != wrapIndex(i-1, me.Length()); j = wrapIndex(j+1, me.Length()) { - jv := me.Vertex(j) - bisectingSegment := &Segment{iv, jv} - dbg("bisectingSegment(%d, %d) = %v", i, j, bisectingSegment) - - //first check to see that it doesn't intersect any other segments - for si := 0; si < me.Length(); si++ { - s := me.Segment(si) - u1, u2 := s.IntersectParameters(bisectingSegment) - if math.IsNaN(u1) || math.IsNaN(u2) || (u1 > 0 && u1 < 1 && u2 > 0 && u2 < 1) { - dbg(" Segment(%d, %d) %v\n%f %f", si, si+1, s, u1, u2) - continue v2 - } else { - dbg(" doesn't intersect %v: %f %f", s, u1, u2) - } - } - - //second check to see that it is in the interior of the polygon - midCoord := bisectingSegment.Extrapolate(0.5) - if !me.ContainsCoord(midCoord) { - dbg(" poly contains %v", midCoord) - continue v2 - } - - dbg(" Segment %v is good", bisectingSegment) - - p1, p2 := me.Bisect(i, j) - t1, ok1 := p1.Triangles() - t2, ok2 := p2.Triangles() - tris = append(t1, t2...) - ok = ok1 && ok2 - return - } - } - - dbg("failed with %v", me) - //panic("couldn't find any valid bisecting segment") - - return -} diff --git a/vendor/github.com/skelterjohn/geom/rect.go b/vendor/github.com/skelterjohn/geom/rect.go deleted file mode 100644 index d7b4b58..0000000 --- a/vendor/github.com/skelterjohn/geom/rect.go +++ /dev/null @@ -1,161 +0,0 @@ -// Copyright 2012 The geom Authors. All rights reserved. -// Use of this source code is governed by a license that -// can be found in the LICENSE file. - -package geom - -import ( - "fmt" - "math" -) - -type Rect struct { - Min, Max Coord -} - -// this rect contains nothing -func NilRect() (r Rect) { - r.Min.X = math.Inf(1) - r.Min.Y = math.Inf(1) - r.Max.X = math.Inf(-1) - r.Max.Y = math.Inf(-1) - return -} - -func (r Rect) Width() float64 { - return r.Max.X - r.Min.X -} - -func (r Rect) Height() float64 { - return r.Max.Y - r.Min.Y -} - -func (r Rect) Size() (w, h float64) { - return r.Max.X - r.Min.X, r.Max.Y - r.Min.Y -} - -func (r Rect) Center() (center Coord) { - center.X = 0.5 * (r.Min.X + r.Max.X) - center.Y = 0.5 * (r.Min.Y + r.Max.Y) - return -} - -func (r Rect) ContainsCoord(p Coord) bool { - return r.Min.QuadPP(p) && r.Max.QuadMM(p) -} - -func (r Rect) ContainsRect(o Rect) bool { - return r.ContainsCoord(o.Min) && r.ContainsCoord(o.Max) -} - -func (r *Rect) Translate(offset Coord) { - r.Min = r.Min.Plus(offset) - r.Max = r.Max.Plus(offset) -} - -func (r *Rect) Scale(xf, yf float64) { - r.Min.Scale(xf, yf) - r.Max.Scale(xf, yf) - if xf < 0 { - r.Min.X, r.Max.X = r.Max.X, r.Min.X - } - if yf < 0 { - r.Min.Y, r.Max.Y = r.Max.Y, r.Min.Y - } -} - -func (r *Rect) ExpandToContain(ch <-chan Coord) { - for p := range ch { - r.ExpandToContainCoord(p) - } -} - -func (r *Rect) ExpandToContainCoord(p Coord) { - r.Min.X = minf(r.Min.X, p.X) - r.Min.Y = minf(r.Min.Y, p.Y) - r.Max.X = maxf(r.Max.X, p.X) - r.Max.Y = maxf(r.Max.Y, p.Y) -} - -func (r *Rect) ExpandToContainRect(q Rect) { - r.ExpandToContainCoord(q.Min) - r.ExpandToContainCoord(q.Max) -} - -func (r Rect) Bounds() (bounds Rect) { - bounds = r - return -} - -func (r Rect) Equals(oi interface{}) bool { - or, ok := oi.(Rect) - return ok && RectsEqual(r, or) -} - -func RectsIntersect(r1, r2 Rect) bool { - ov := func(min1, max1, min2, max2 float64) (overlap bool) { - if min1 <= min2 && max1 >= min2 { - return true - } - if min1 <= max2 && max1 >= max2 { - return true - } - if min2 <= min1 && max2 >= min1 { - return true - } - if min2 <= max1 && max2 >= max1 { - return true - } - return false - } - dbg("RI(%v, %v)", r1, r2) - xoverlap := ov(r1.Min.X, r1.Max.X, r2.Min.X, r2.Max.X) - yoverlap := ov(r1.Min.Y, r1.Max.Y, r2.Min.Y, r2.Max.Y) - dbg("%v %v", xoverlap, yoverlap) - return xoverlap && yoverlap -} - -func RectsIntersectStrict(r1, r2 Rect) bool { - ov := func(min1, max1, min2, max2 float64) (overlap bool) { - if min1 < min2 && max1 > min2 { - return true - } - if min1 < max2 && max1 > max2 { - return true - } - if min2 < min1 && max2 > min1 { - return true - } - if min2 < max1 && max2 > max1 { - return true - } - return false - } - dbg("RI(%v, %v)", r1, r2) - xoverlap := ov(r1.Min.X, r1.Max.X, r2.Min.X, r2.Max.X) - yoverlap := ov(r1.Min.Y, r1.Max.Y, r2.Min.Y, r2.Max.Y) - dbg("%v %v", xoverlap, yoverlap) - return xoverlap && yoverlap -} - -func RectsIntersection(r1, r2 Rect) (ri Rect) { - ri.Min.X = math.Max(r1.Min.X, r2.Min.X) - ri.Min.Y = math.Max(r1.Min.Y, r2.Min.Y) - ri.Max.X = math.Min(r1.Max.X, r2.Max.X) - ri.Max.Y = math.Min(r1.Max.Y, r2.Max.Y) - return -} - -func RectsEqual(r1, r2 Rect) bool { - if !r1.Min.EqualsCoord(r2.Min) { - return false - } - if !r1.Max.EqualsCoord(r2.Max) { - return false - } - return true -} - -func (r Rect) String() string { - return fmt.Sprintf("{%v %v}", r.Min, r.Max) -} diff --git a/vendor/github.com/skelterjohn/geom/segment.go b/vendor/github.com/skelterjohn/geom/segment.go deleted file mode 100644 index 56f90ac..0000000 --- a/vendor/github.com/skelterjohn/geom/segment.go +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2012 The geom Authors. All rights reserved. -// Use of this source code is governed by a license that -// can be found in the LICENSE file. - -package geom - -type Segment struct { - A, B Coord -} - -func (s *Segment) IntersectParameters(t *Segment) (ps, pt float64) { - x1, y1 := s.A.X, s.A.Y - x2, y2 := s.B.X, s.B.Y - x3, y3 := t.A.X, t.A.Y - x4, y4 := t.B.X, t.B.Y - - x4x3 := x4 - x3 - y1y3 := y1 - y3 - y4y3 := y4 - y3 - x1x3 := x1 - x3 - x2x1 := x2 - x1 - y2y1 := y2 - y1 - - ps = (x4x3*y1y3 - y4y3*x1x3) / (y4y3*x2x1 - x4x3*y2y1) - pt = (x2x1*y1y3 - y2y1*x1x3) / (y4y3*x2x1 - x4x3*y2y1) - - return -} - -func (s *Segment) Intersection(t *Segment) (p Coord, ok bool) { - ps, pt := s.IntersectParameters(t) - - p.X = s.A.X + ps*(s.B.X-s.A.X) - p.Y = s.A.Y + ps*(s.B.Y-s.A.Y) - - ok = ps >= 0 && ps <= 1 && pt >= 0 && pt <= 1 - - return -} - -func (s *Segment) Extrapolate(t float64) (p Coord) { - p.X = s.A.X + t*(s.B.X-s.A.X) - p.Y = s.A.Y + t*(s.B.Y-s.A.Y) - return -} diff --git a/vendor/github.com/skelterjohn/geom/tri.go b/vendor/github.com/skelterjohn/geom/tri.go deleted file mode 100644 index f8df8e2..0000000 --- a/vendor/github.com/skelterjohn/geom/tri.go +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2012 The geom Authors. All rights reserved. -// Use of this source code is governed by a license that -// can be found in the LICENSE file. - -package geom - -type Triangle struct { - A, B, C Coord -} - -func (me *Triangle) Bounds() (bounds *Rect) { - bounds = &Rect{me.A, me.A} - bounds.ExpandToContainCoord(me.B) - bounds.ExpandToContainCoord(me.C) - return -} - -func (me *Triangle) Equals(oi interface{}) bool { - ot, ok := oi.(*Triangle) - if !ok { - return false - } - if me.A.EqualsCoord(ot.A) { - if me.B.EqualsCoord(ot.B) { - return me.C.EqualsCoord(ot.C) - } - if me.B.EqualsCoord(ot.C) { - return me.C.EqualsCoord(ot.B) - } - } - if me.A.EqualsCoord(ot.B) { - if me.B.EqualsCoord(ot.A) { - return me.C.EqualsCoord(ot.C) - } - if me.B.EqualsCoord(ot.C) { - return me.C.EqualsCoord(ot.A) - } - } - if me.A.EqualsCoord(ot.C) { - if me.B.EqualsCoord(ot.B) { - return me.C.EqualsCoord(ot.A) - } - if me.B.EqualsCoord(ot.A) { - return me.C.EqualsCoord(ot.B) - } - } - return false -} - -func (me *Triangle) Vertices() (vertices []Coord) { - vertices = []Coord{me.A, me.B, me.C} - return -} - -func (me *Triangle) ContainsCoord(p Coord) bool { - leftA := CrossProduct(me.B.Minus(me.A), p.Minus(me.A)) < 0 - leftB := CrossProduct(me.C.Minus(me.B), p.Minus(me.B)) < 0 - leftC := CrossProduct(me.A.Minus(me.C), p.Minus(me.C)) < 0 - return leftA == leftB && leftA == leftC -} - -func (me *Triangle) HasVertex(v Coord) bool { - return v.EqualsCoord(me.A) || v.EqualsCoord(me.B) || v.EqualsCoord(me.C) -} diff --git a/vendor/github.com/skelterjohn/geom/util.go b/vendor/github.com/skelterjohn/geom/util.go deleted file mode 100644 index 8f01557..0000000 --- a/vendor/github.com/skelterjohn/geom/util.go +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2012 The geom Authors. All rights reserved. -// Use of this source code is governed by a license that -// can be found in the LICENSE file. - -package geom - -func minf(x, y float64) (r float64) { - r = x - if r > y { - r = y - } - return -} - -func maxf(x, y float64) (r float64) { - r = x - if r < y { - r = y - } - return -} diff --git a/vendor/github.com/tidwall/gjson/LICENSE b/vendor/github.com/tidwall/gjson/LICENSE deleted file mode 100644 index 58f5819..0000000 --- a/vendor/github.com/tidwall/gjson/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 Josh Baker - -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/vendor/github.com/tidwall/gjson/README.md b/vendor/github.com/tidwall/gjson/README.md deleted file mode 100644 index cab0f9f..0000000 --- a/vendor/github.com/tidwall/gjson/README.md +++ /dev/null @@ -1,491 +0,0 @@ -

-GJSON -
-Build Status -GoDoc -GJSON Playground -

- - - -

get json values quickly

- -GJSON is a Go package that provides a [fast](#performance) and [simple](#get-a-value) way to get values from a json document. -It has features such as [one line retrieval](#get-a-value), [dot notation paths](#path-syntax), [iteration](#iterate-through-an-object-or-array), and [parsing json lines](#json-lines). - -Also check out [SJSON](https://github.com/tidwall/sjson) for modifying json, and the [JJ](https://github.com/tidwall/jj) command line tool. - -Getting Started -=============== - -## Installing - -To start using GJSON, install Go and run `go get`: - -```sh -$ go get -u github.com/tidwall/gjson -``` - -This will retrieve the library. - -## Get a value -Get searches json for the specified path. A path is in dot syntax, such as "name.last" or "age". When the value is found it's returned immediately. - -```go -package main - -import "github.com/tidwall/gjson" - -const json = `{"name":{"first":"Janet","last":"Prichard"},"age":47}` - -func main() { - value := gjson.Get(json, "name.last") - println(value.String()) -} -``` - -This will print: - -``` -Prichard -``` -*There's also the [GetMany](#get-multiple-values-at-once) function to get multiple values at once, and [GetBytes](#working-with-bytes) for working with JSON byte slices.* - -## Path Syntax - -Below is a quick overview of the path syntax, for more complete information please -check out [GJSON Syntax](SYNTAX.md). - -A path is a series of keys separated by a dot. -A key may contain special wildcard characters '\*' and '?'. -To access an array value use the index as the key. -To get the number of elements in an array or to access a child path, use the '#' character. -The dot and wildcard characters can be escaped with '\\'. - -```json -{ - "name": {"first": "Tom", "last": "Anderson"}, - "age":37, - "children": ["Sara","Alex","Jack"], - "fav.movie": "Deer Hunter", - "friends": [ - {"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]}, - {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]}, - {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]} - ] -} -``` -``` -"name.last" >> "Anderson" -"age" >> 37 -"children" >> ["Sara","Alex","Jack"] -"children.#" >> 3 -"children.1" >> "Alex" -"child*.2" >> "Jack" -"c?ildren.0" >> "Sara" -"fav\.movie" >> "Deer Hunter" -"friends.#.first" >> ["Dale","Roger","Jane"] -"friends.1.last" >> "Craig" -``` - -You can also query an array for the first match by using `#(...)`, or find all -matches with `#(...)#`. Queries support the `==`, `!=`, `<`, `<=`, `>`, `>=` -comparison operators and the simple pattern matching `%` (like) and `!%` -(not like) operators. - -``` -friends.#(last=="Murphy").first >> "Dale" -friends.#(last=="Murphy")#.first >> ["Dale","Jane"] -friends.#(age>45)#.last >> ["Craig","Murphy"] -friends.#(first%"D*").last >> "Murphy" -friends.#(first!%"D*").last >> "Craig" -friends.#(nets.#(=="fb"))#.first >> ["Dale","Roger"] -``` - -*Please note that prior to v1.3.0, queries used the `#[...]` brackets. This was -changed in v1.3.0 as to avoid confusion with the new -[multipath](SYNTAX.md#multipaths) syntax. For backwards compatibility, -`#[...]` will continue to work until the next major release.* - -## Result Type - -GJSON supports the json types `string`, `number`, `bool`, and `null`. -Arrays and Objects are returned as their raw json types. - -The `Result` type holds one of these: - -``` -bool, for JSON booleans -float64, for JSON numbers -string, for JSON string literals -nil, for JSON null -``` - -To directly access the value: - -```go -result.Type // can be String, Number, True, False, Null, or JSON -result.Str // holds the string -result.Num // holds the float64 number -result.Raw // holds the raw json -result.Index // index of raw value in original json, zero means index unknown -``` - -There are a variety of handy functions that work on a result: - -```go -result.Exists() bool -result.Value() interface{} -result.Int() int64 -result.Uint() uint64 -result.Float() float64 -result.String() string -result.Bool() bool -result.Time() time.Time -result.Array() []gjson.Result -result.Map() map[string]gjson.Result -result.Get(path string) Result -result.ForEach(iterator func(key, value Result) bool) -result.Less(token Result, caseSensitive bool) bool -``` - -The `result.Value()` function returns an `interface{}` which requires type assertion and is one of the following Go types: - -The `result.Array()` function returns back an array of values. -If the result represents a non-existent value, then an empty array will be returned. -If the result is not a JSON array, the return value will be an array containing one result. - -```go -boolean >> bool -number >> float64 -string >> string -null >> nil -array >> []interface{} -object >> map[string]interface{} -``` - -### 64-bit integers - -The `result.Int()` and `result.Uint()` calls are capable of reading all 64 bits, allowing for large JSON integers. - -```go -result.Int() int64 // -9223372036854775808 to 9223372036854775807 -result.Uint() int64 // 0 to 18446744073709551615 -``` - -## Modifiers and path chaining - -New in version 1.2 is support for modifier functions and path chaining. - -A modifier is a path component that performs custom processing on the -json. - -Multiple paths can be "chained" together using the pipe character. -This is useful for getting results from a modified query. - -For example, using the built-in `@reverse` modifier on the above json document, -we'll get `children` array and reverse the order: - -``` -"children|@reverse" >> ["Jack","Alex","Sara"] -"children|@reverse|0" >> "Jack" -``` - -There are currently three built-in modifiers: - -- `@reverse`: Reverse an array or the members of an object. -- `@ugly`: Remove all whitespace from a json document. -- `@pretty`: Make the json document more human readable. - -### Modifier arguments - -A modifier may accept an optional argument. The argument can be a valid JSON -document or just characters. - -For example, the `@pretty` modifier takes a json object as its argument. - -``` -@pretty:{"sortKeys":true} -``` - -Which makes the json pretty and orders all of its keys. - -```json -{ - "age":37, - "children": ["Sara","Alex","Jack"], - "fav.movie": "Deer Hunter", - "friends": [ - {"age": 44, "first": "Dale", "last": "Murphy"}, - {"age": 68, "first": "Roger", "last": "Craig"}, - {"age": 47, "first": "Jane", "last": "Murphy"} - ], - "name": {"first": "Tom", "last": "Anderson"} -} -``` - -*The full list of `@pretty` options are `sortKeys`, `indent`, `prefix`, and `width`. -Please see [Pretty Options](https://github.com/tidwall/pretty#customized-output) for more information.* - -### Custom modifiers - -You can also add custom modifiers. - -For example, here we create a modifier that makes the entire json document upper -or lower case. - -```go -gjson.AddModifier("case", func(json, arg string) string { - if arg == "upper" { - return strings.ToUpper(json) - } - if arg == "lower" { - return strings.ToLower(json) - } - return json -}) -``` - -``` -"children|@case:upper" >> ["SARA","ALEX","JACK"] -"children|@case:lower|@reverse" >> ["jack","alex","sara"] -``` - -## JSON Lines - -There's support for [JSON Lines](http://jsonlines.org/) using the `..` prefix, which treats a multilined document as an array. - -For example: - -``` -{"name": "Gilbert", "age": 61} -{"name": "Alexa", "age": 34} -{"name": "May", "age": 57} -{"name": "Deloise", "age": 44} -``` - -``` -..# >> 4 -..1 >> {"name": "Alexa", "age": 34} -..3 >> {"name": "Deloise", "age": 44} -..#.name >> ["Gilbert","Alexa","May","Deloise"] -..#(name="May").age >> 57 -``` - -The `ForEachLines` function will iterate through JSON lines. - -```go -gjson.ForEachLine(json, func(line gjson.Result) bool{ - println(line.String()) - return true -}) -``` - -## Get nested array values - -Suppose you want all the last names from the following json: - -```json -{ - "programmers": [ - { - "firstName": "Janet", - "lastName": "McLaughlin", - }, { - "firstName": "Elliotte", - "lastName": "Hunter", - }, { - "firstName": "Jason", - "lastName": "Harold", - } - ] -} -``` - -You would use the path "programmers.#.lastName" like such: - -```go -result := gjson.Get(json, "programmers.#.lastName") -for _, name := range result.Array() { - println(name.String()) -} -``` - -You can also query an object inside an array: - -```go -name := gjson.Get(json, `programmers.#(lastName="Hunter").firstName`) -println(name.String()) // prints "Elliotte" -``` - -## Iterate through an object or array - -The `ForEach` function allows for quickly iterating through an object or array. -The key and value are passed to the iterator function for objects. -Only the value is passed for arrays. -Returning `false` from an iterator will stop iteration. - -```go -result := gjson.Get(json, "programmers") -result.ForEach(func(key, value gjson.Result) bool { - println(value.String()) - return true // keep iterating -}) -``` - -## Simple Parse and Get - -There's a `Parse(json)` function that will do a simple parse, and `result.Get(path)` that will search a result. - -For example, all of these will return the same result: - -```go -gjson.Parse(json).Get("name").Get("last") -gjson.Get(json, "name").Get("last") -gjson.Get(json, "name.last") -``` - -## Check for the existence of a value - -Sometimes you just want to know if a value exists. - -```go -value := gjson.Get(json, "name.last") -if !value.Exists() { - println("no last name") -} else { - println(value.String()) -} - -// Or as one step -if gjson.Get(json, "name.last").Exists() { - println("has a last name") -} -``` - -## Validate JSON - -The `Get*` and `Parse*` functions expects that the json is well-formed. Bad json will not panic, but it may return back unexpected results. - -If you are consuming JSON from an unpredictable source then you may want to validate prior to using GJSON. - -```go -if !gjson.Valid(json) { - return errors.New("invalid json") -} -value := gjson.Get(json, "name.last") -``` - -## Unmarshal to a map - -To unmarshal to a `map[string]interface{}`: - -```go -m, ok := gjson.Parse(json).Value().(map[string]interface{}) -if !ok { - // not a map -} -``` - -## Working with Bytes - -If your JSON is contained in a `[]byte` slice, there's the [GetBytes](https://godoc.org/github.com/tidwall/gjson#GetBytes) function. This is preferred over `Get(string(data), path)`. - -```go -var json []byte = ... -result := gjson.GetBytes(json, path) -``` - -If you are using the `gjson.GetBytes(json, path)` function and you want to avoid converting `result.Raw` to a `[]byte`, then you can use this pattern: - -```go -var json []byte = ... -result := gjson.GetBytes(json, path) -var raw []byte -if result.Index > 0 { - raw = json[result.Index:result.Index+len(result.Raw)] -} else { - raw = []byte(result.Raw) -} -``` - -This is a best-effort no allocation sub slice of the original json. This method utilizes the `result.Index` field, which is the position of the raw data in the original json. It's possible that the value of `result.Index` equals zero, in which case the `result.Raw` is converted to a `[]byte`. - -## Get multiple values at once - -The `GetMany` function can be used to get multiple values at the same time. - -```go -results := gjson.GetMany(json, "name.first", "name.last", "age") -``` - -The return value is a `[]Result`, which will always contain exactly the same number of items as the input paths. - -## Performance - -Benchmarks of GJSON alongside [encoding/json](https://golang.org/pkg/encoding/json/), -[ffjson](https://github.com/pquerna/ffjson), -[EasyJSON](https://github.com/mailru/easyjson), -[jsonparser](https://github.com/buger/jsonparser), -and [json-iterator](https://github.com/json-iterator/go) - -``` -BenchmarkGJSONGet-8 3000000 372 ns/op 0 B/op 0 allocs/op -BenchmarkGJSONUnmarshalMap-8 900000 4154 ns/op 1920 B/op 26 allocs/op -BenchmarkJSONUnmarshalMap-8 600000 9019 ns/op 3048 B/op 69 allocs/op -BenchmarkJSONDecoder-8 300000 14120 ns/op 4224 B/op 184 allocs/op -BenchmarkFFJSONLexer-8 1500000 3111 ns/op 896 B/op 8 allocs/op -BenchmarkEasyJSONLexer-8 3000000 887 ns/op 613 B/op 6 allocs/op -BenchmarkJSONParserGet-8 3000000 499 ns/op 21 B/op 0 allocs/op -BenchmarkJSONIterator-8 3000000 812 ns/op 544 B/op 9 allocs/op -``` - -JSON document used: - -```json -{ - "widget": { - "debug": "on", - "window": { - "title": "Sample Konfabulator Widget", - "name": "main_window", - "width": 500, - "height": 500 - }, - "image": { - "src": "Images/Sun.png", - "hOffset": 250, - "vOffset": 250, - "alignment": "center" - }, - "text": { - "data": "Click Here", - "size": 36, - "style": "bold", - "vOffset": 100, - "alignment": "center", - "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" - } - } -} -``` - -Each operation was rotated though one of the following search paths: - -``` -widget.window.name -widget.image.hOffset -widget.text.onMouseUp -``` - -*These benchmarks were run on a MacBook Pro 15" 2.8 GHz Intel Core i7 using Go 1.8 and can be be found [here](https://github.com/tidwall/gjson-benchmarks).* - - -## Contact -Josh Baker [@tidwall](http://twitter.com/tidwall) - -## License - -GJSON source code is available under the MIT [License](/LICENSE). diff --git a/vendor/github.com/tidwall/gjson/SYNTAX.md b/vendor/github.com/tidwall/gjson/SYNTAX.md deleted file mode 100644 index a57a4d6..0000000 --- a/vendor/github.com/tidwall/gjson/SYNTAX.md +++ /dev/null @@ -1,265 +0,0 @@ -# GJSON Path Syntax - -A GJSON Path is a text string syntax that describes a search pattern for quickly retreiving values from a JSON payload. - -This document is designed to explain the structure of a GJSON Path through examples. - -- [Path structure](#path-structure) -- [Basic](#basic) -- [Wildcards](#wildcards) -- [Escape Character](#escape-character) -- [Arrays](#arrays) -- [Queries](#queries) -- [Dot vs Pipe](#dot-vs-pipe) -- [Modifiers](#modifiers) -- [Multipaths](#multipaths) - -The definitive implemenation is [github.com/tidwall/gjson](https://github.com/tidwall/gjson). -Use the [GJSON Playground](https://gjson.dev) to experiment with the syntax online. - - -## Path structure - -A GJSON Path is intended to be easily expressed as a series of components seperated by a `.` character. - -Along with `.` character, there are a few more that have special meaning, including `|`, `#`, `@`, `\`, `*`, and `?`. - -## Example - -Given this JSON - -```json -{ - "name": {"first": "Tom", "last": "Anderson"}, - "age":37, - "children": ["Sara","Alex","Jack"], - "fav.movie": "Deer Hunter", - "friends": [ - {"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]}, - {"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]}, - {"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]} - ] -} -``` - -The following GJSON Paths evaluate to the accompanying values. - -### Basic - -In many cases you'll just want to retreive values by object name or array index. - -```go -name.last "Anderson" -name.first "Tom" -age 37 -children ["Sara","Alex","Jack"] -children.0 "Sara" -children.1 "Alex" -friends.1 {"first": "Roger", "last": "Craig", "age": 68} -friends.1.first "Roger" -``` - -### Wildcards - -A key may contain the special wildcard characters `*` and `?`. -The `*` will match on any zero+ characters, and `?` matches on any one character. - -```go -child*.2 "Jack" -c?ildren.0 "Sara" -``` - -### Escape character - -Special purpose characters, such as `.`, `*`, and `?` can be escaped with `\`. - -```go -fav\.movie "Deer Hunter" -``` - -### Arrays - -The `#` character allows for digging into JSON Arrays. - -To get the length of an array you'll just use the `#` all by itself. - -```go -friends.# 3 -friends.#.age [44,68,47] -``` - -### Queries - -You can also query an array for the first match by using `#(...)`, or find all matches with `#(...)#`. -Queries support the `==`, `!=`, `<`, `<=`, `>`, `>=` comparison operators, -and the simple pattern matching `%` (like) and `!%` (not like) operators. - -```go -friends.#(last=="Murphy").first "Dale" -friends.#(last=="Murphy")#.first ["Dale","Jane"] -friends.#(age>45)#.last ["Craig","Murphy"] -friends.#(first%"D*").last "Murphy" -friends.#(first!%"D*").last "Craig" -``` - -To query for a non-object value in an array, you can forgo the string to the right of the operator. - -```go -children.#(!%"*a*") "Alex" -children.#(%"*a*")# ["Sara","Jack"] -``` - -Nested queries are allowed. - -```go -friends.#(nets.#(=="fb"))#.first >> ["Dale","Roger"] -``` - -*Please note that prior to v1.3.0, queries used the `#[...]` brackets. This was -changed in v1.3.0 as to avoid confusion with the new [multipath](#multipaths) -syntax. For backwards compatibility, `#[...]` will continue to work until the -next major release.* - -### Dot vs Pipe - -The `.` is standard separator, but it's also possible to use a `|`. -In most cases they both end up returning the same results. -The cases where`|` differs from `.` is when it's used after the `#` for [Arrays](#arrays) and [Queries](#queries). - -Here are some examples - -```go -friends.0.first "Dale" -friends|0.first "Dale" -friends.0|first "Dale" -friends|0|first "Dale" -friends|# 3 -friends.# 3 -friends.#(last="Murphy")# [{"first": "Dale", "last": "Murphy", "age": 44},{"first": "Jane", "last": "Murphy", "age": 47}] -friends.#(last="Murphy")#.first ["Dale","Jane"] -friends.#(last="Murphy")#|first -friends.#(last="Murphy")#.0 [] -friends.#(last="Murphy")#|0 {"first": "Dale", "last": "Murphy", "age": 44} -friends.#(last="Murphy")#.# [] -friends.#(last="Murphy")#|# 2 -``` - -Let's break down a few of these. - -The path `friends.#(last="Murphy")#` all by itself results in - -```json -[{"first": "Dale", "last": "Murphy", "age": 44},{"first": "Jane", "last": "Murphy", "age": 47}] -``` - -The `.first` suffix will process the `first` path on each array element *before* returning the results. Which becomes - -```json -["Dale","Jane"] -``` - -But the `|first` suffix actually processes the `first` path *after* the previous result. -Since the previous result is an array, not an object, it's not possible to process -because `first` does not exist. - -Yet, `|0` suffix returns - -```json -{"first": "Dale", "last": "Murphy", "age": 44} -``` - -Because `0` is the first index of the previous result. - -### Modifiers - -A modifier is a path component that performs custom processing on the JSON. - -For example, using the built-in `@reverse` modifier on the above JSON payload will reverse the `children` array: - -```go -children.@reverse ["Jack","Alex","Sara"] -children.@reverse.0 "Jack" -``` - -There are currently three built-in modifiers: - -- `@reverse`: Reverse an array or the members of an object. -- `@ugly`: Remove all whitespace from JSON. -- `@pretty`: Make the JSON more human readable. - -#### Modifier arguments - -A modifier may accept an optional argument. The argument can be a valid JSON payload or just characters. - -For example, the `@pretty` modifier takes a json object as its argument. - -``` -@pretty:{"sortKeys":true} -``` - -Which makes the json pretty and orders all of its keys. - -```json -{ - "age":37, - "children": ["Sara","Alex","Jack"], - "fav.movie": "Deer Hunter", - "friends": [ - {"age": 44, "first": "Dale", "last": "Murphy"}, - {"age": 68, "first": "Roger", "last": "Craig"}, - {"age": 47, "first": "Jane", "last": "Murphy"} - ], - "name": {"first": "Tom", "last": "Anderson"} -} -``` - -*The full list of `@pretty` options are `sortKeys`, `indent`, `prefix`, and `width`. -Please see [Pretty Options](https://github.com/tidwall/pretty#customized-output) for more information.* - -#### Custom modifiers - -You can also add custom modifiers. - -For example, here we create a modifier which makes the entire JSON payload upper or lower case. - -```go -gjson.AddModifier("case", func(json, arg string) string { - if arg == "upper" { - return strings.ToUpper(json) - } - if arg == "lower" { - return strings.ToLower(json) - } - return json -}) -"children.@case:upper" ["SARA","ALEX","JACK"] -"children.@case:lower.@reverse" ["jack","alex","sara"] -``` - -### Multipaths - -Starting with v1.3.0, GJSON added the ability to join multiple paths together -to form new documents. Wrapping comma-separated paths between `{...}` or -`[...]` will result in a new array or object, respectively. - -For example, using the given multipath - -``` -{name.first,age,"the_murphys":friends.#(last="Murphy")#.first} -``` - -Here we selected the first name, age, and the first name for friends with the -last name "Murphy". - -You'll notice that an optional key can be provided, in this case -"the_murphys", to force assign a key to a value. Otherwise, the name of the -actual field will be used, in this case "first". If a name cannot be -determined, then "_" is used. - -This results in - -``` -{"first":"Tom","age":37,"the_murphys":["Dale","Jane"]} -``` - - diff --git a/vendor/github.com/tidwall/gjson/gjson.go b/vendor/github.com/tidwall/gjson/gjson.go deleted file mode 100644 index 787d327..0000000 --- a/vendor/github.com/tidwall/gjson/gjson.go +++ /dev/null @@ -1,2826 +0,0 @@ -// Package gjson provides searching for json strings. -package gjson - -import ( - "encoding/base64" - "encoding/json" - "errors" - "reflect" - "strconv" - "strings" - "sync" - "sync/atomic" - "time" - "unicode/utf16" - "unicode/utf8" - - "github.com/tidwall/match" - "github.com/tidwall/pretty" -) - -// Type is Result type -type Type int - -const ( - // Null is a null json value - Null Type = iota - // False is a json false boolean - False - // Number is json number - Number - // String is a json string - String - // True is a json true boolean - True - // JSON is a raw block of JSON - JSON -) - -// String returns a string representation of the type. -func (t Type) String() string { - switch t { - default: - return "" - case Null: - return "Null" - case False: - return "False" - case Number: - return "Number" - case String: - return "String" - case True: - return "True" - case JSON: - return "JSON" - } -} - -// Result represents a json value that is returned from Get(). -type Result struct { - // Type is the json type - Type Type - // Raw is the raw json - Raw string - // Str is the json string - Str string - // Num is the json number - Num float64 - // Index of raw value in original json, zero means index unknown - Index int -} - -// String returns a string representation of the value. -func (t Result) String() string { - switch t.Type { - default: - return "" - case False: - return "false" - case Number: - if len(t.Raw) == 0 { - // calculated result - return strconv.FormatFloat(t.Num, 'f', -1, 64) - } - var i int - if t.Raw[0] == '-' { - i++ - } - for ; i < len(t.Raw); i++ { - if t.Raw[i] < '0' || t.Raw[i] > '9' { - return strconv.FormatFloat(t.Num, 'f', -1, 64) - } - } - return t.Raw - case String: - return t.Str - case JSON: - return t.Raw - case True: - return "true" - } -} - -// Bool returns an boolean representation. -func (t Result) Bool() bool { - switch t.Type { - default: - return false - case True: - return true - case String: - return t.Str != "" && t.Str != "0" && t.Str != "false" - case Number: - return t.Num != 0 - } -} - -// Int returns an integer representation. -func (t Result) Int() int64 { - switch t.Type { - default: - return 0 - case True: - return 1 - case String: - n, _ := parseInt(t.Str) - return n - case Number: - // try to directly convert the float64 to int64 - n, ok := floatToInt(t.Num) - if !ok { - // now try to parse the raw string - n, ok = parseInt(t.Raw) - if !ok { - // fallback to a standard conversion - return int64(t.Num) - } - } - return n - } -} - -// Uint returns an unsigned integer representation. -func (t Result) Uint() uint64 { - switch t.Type { - default: - return 0 - case True: - return 1 - case String: - n, _ := parseUint(t.Str) - return n - case Number: - // try to directly convert the float64 to uint64 - n, ok := floatToUint(t.Num) - if !ok { - // now try to parse the raw string - n, ok = parseUint(t.Raw) - if !ok { - // fallback to a standard conversion - return uint64(t.Num) - } - } - return n - } -} - -// Float returns an float64 representation. -func (t Result) Float() float64 { - switch t.Type { - default: - return 0 - case True: - return 1 - case String: - n, _ := strconv.ParseFloat(t.Str, 64) - return n - case Number: - return t.Num - } -} - -// Time returns a time.Time representation. -func (t Result) Time() time.Time { - res, _ := time.Parse(time.RFC3339, t.String()) - return res -} - -// Array returns back an array of values. -// If the result represents a non-existent value, then an empty array will be -// returned. If the result is not a JSON array, the return value will be an -// array containing one result. -func (t Result) Array() []Result { - if t.Type == Null { - return []Result{} - } - if t.Type != JSON { - return []Result{t} - } - r := t.arrayOrMap('[', false) - return r.a -} - -// IsObject returns true if the result value is a JSON object. -func (t Result) IsObject() bool { - return t.Type == JSON && len(t.Raw) > 0 && t.Raw[0] == '{' -} - -// IsArray returns true if the result value is a JSON array. -func (t Result) IsArray() bool { - return t.Type == JSON && len(t.Raw) > 0 && t.Raw[0] == '[' -} - -// ForEach iterates through values. -// If the result represents a non-existent value, then no values will be -// iterated. If the result is an Object, the iterator will pass the key and -// value of each item. If the result is an Array, the iterator will only pass -// the value of each item. If the result is not a JSON array or object, the -// iterator will pass back one value equal to the result. -func (t Result) ForEach(iterator func(key, value Result) bool) { - if !t.Exists() { - return - } - if t.Type != JSON { - iterator(Result{}, t) - return - } - json := t.Raw - var keys bool - var i int - var key, value Result - for ; i < len(json); i++ { - if json[i] == '{' { - i++ - key.Type = String - keys = true - break - } else if json[i] == '[' { - i++ - break - } - if json[i] > ' ' { - return - } - } - var str string - var vesc bool - var ok bool - for ; i < len(json); i++ { - if keys { - if json[i] != '"' { - continue - } - s := i - i, str, vesc, ok = parseString(json, i+1) - if !ok { - return - } - if vesc { - key.Str = unescape(str[1 : len(str)-1]) - } else { - key.Str = str[1 : len(str)-1] - } - key.Raw = str - key.Index = s - } - for ; i < len(json); i++ { - if json[i] <= ' ' || json[i] == ',' || json[i] == ':' { - continue - } - break - } - s := i - i, value, ok = parseAny(json, i, true) - if !ok { - return - } - value.Index = s - if !iterator(key, value) { - return - } - } -} - -// Map returns back an map of values. The result should be a JSON array. -func (t Result) Map() map[string]Result { - if t.Type != JSON { - return map[string]Result{} - } - r := t.arrayOrMap('{', false) - return r.o -} - -// Get searches result for the specified path. -// The result should be a JSON array or object. -func (t Result) Get(path string) Result { - return Get(t.Raw, path) -} - -type arrayOrMapResult struct { - a []Result - ai []interface{} - o map[string]Result - oi map[string]interface{} - vc byte -} - -func (t Result) arrayOrMap(vc byte, valueize bool) (r arrayOrMapResult) { - var json = t.Raw - var i int - var value Result - var count int - var key Result - if vc == 0 { - for ; i < len(json); i++ { - if json[i] == '{' || json[i] == '[' { - r.vc = json[i] - i++ - break - } - if json[i] > ' ' { - goto end - } - } - } else { - for ; i < len(json); i++ { - if json[i] == vc { - i++ - break - } - if json[i] > ' ' { - goto end - } - } - r.vc = vc - } - if r.vc == '{' { - if valueize { - r.oi = make(map[string]interface{}) - } else { - r.o = make(map[string]Result) - } - } else { - if valueize { - r.ai = make([]interface{}, 0) - } else { - r.a = make([]Result, 0) - } - } - for ; i < len(json); i++ { - if json[i] <= ' ' { - continue - } - // get next value - if json[i] == ']' || json[i] == '}' { - break - } - switch json[i] { - default: - if (json[i] >= '0' && json[i] <= '9') || json[i] == '-' { - value.Type = Number - value.Raw, value.Num = tonum(json[i:]) - value.Str = "" - } else { - continue - } - case '{', '[': - value.Type = JSON - value.Raw = squash(json[i:]) - value.Str, value.Num = "", 0 - case 'n': - value.Type = Null - value.Raw = tolit(json[i:]) - value.Str, value.Num = "", 0 - case 't': - value.Type = True - value.Raw = tolit(json[i:]) - value.Str, value.Num = "", 0 - case 'f': - value.Type = False - value.Raw = tolit(json[i:]) - value.Str, value.Num = "", 0 - case '"': - value.Type = String - value.Raw, value.Str = tostr(json[i:]) - value.Num = 0 - } - i += len(value.Raw) - 1 - - if r.vc == '{' { - if count%2 == 0 { - key = value - } else { - if valueize { - if _, ok := r.oi[key.Str]; !ok { - r.oi[key.Str] = value.Value() - } - } else { - if _, ok := r.o[key.Str]; !ok { - r.o[key.Str] = value - } - } - } - count++ - } else { - if valueize { - r.ai = append(r.ai, value.Value()) - } else { - r.a = append(r.a, value) - } - } - } -end: - return -} - -// Parse parses the json and returns a result. -// -// This function expects that the json is well-formed, and does not validate. -// Invalid json will not panic, but it may return back unexpected results. -// If you are consuming JSON from an unpredictable source then you may want to -// use the Valid function first. -func Parse(json string) Result { - var value Result - for i := 0; i < len(json); i++ { - if json[i] == '{' || json[i] == '[' { - value.Type = JSON - value.Raw = json[i:] // just take the entire raw - break - } - if json[i] <= ' ' { - continue - } - switch json[i] { - default: - if (json[i] >= '0' && json[i] <= '9') || json[i] == '-' { - value.Type = Number - value.Raw, value.Num = tonum(json[i:]) - } else { - return Result{} - } - case 'n': - value.Type = Null - value.Raw = tolit(json[i:]) - case 't': - value.Type = True - value.Raw = tolit(json[i:]) - case 'f': - value.Type = False - value.Raw = tolit(json[i:]) - case '"': - value.Type = String - value.Raw, value.Str = tostr(json[i:]) - } - break - } - return value -} - -// ParseBytes parses the json and returns a result. -// If working with bytes, this method preferred over Parse(string(data)) -func ParseBytes(json []byte) Result { - return Parse(string(json)) -} - -func squash(json string) string { - // expects that the lead character is a '[' or '{' or '(' - // squash the value, ignoring all nested arrays and objects. - // the first '[' or '{' or '(', has already been read - depth := 1 - for i := 1; i < len(json); i++ { - if json[i] >= '"' && json[i] <= '}' { - switch json[i] { - case '"': - i++ - s2 := i - for ; i < len(json); i++ { - if json[i] > '\\' { - continue - } - if json[i] == '"' { - // look for an escaped slash - if json[i-1] == '\\' { - n := 0 - for j := i - 2; j > s2-1; j-- { - if json[j] != '\\' { - break - } - n++ - } - if n%2 == 0 { - continue - } - } - break - } - } - case '{', '[', '(': - depth++ - case '}', ']', ')': - depth-- - if depth == 0 { - return json[:i+1] - } - } - } - } - return json -} - -func tonum(json string) (raw string, num float64) { - for i := 1; i < len(json); i++ { - // less than dash might have valid characters - if json[i] <= '-' { - if json[i] <= ' ' || json[i] == ',' { - // break on whitespace and comma - raw = json[:i] - num, _ = strconv.ParseFloat(raw, 64) - return - } - // could be a '+' or '-'. let's assume so. - continue - } - if json[i] < ']' { - // probably a valid number - continue - } - if json[i] == 'e' || json[i] == 'E' { - // allow for exponential numbers - continue - } - // likely a ']' or '}' - raw = json[:i] - num, _ = strconv.ParseFloat(raw, 64) - return - } - raw = json - num, _ = strconv.ParseFloat(raw, 64) - return -} - -func tolit(json string) (raw string) { - for i := 1; i < len(json); i++ { - if json[i] < 'a' || json[i] > 'z' { - return json[:i] - } - } - return json -} - -func tostr(json string) (raw string, str string) { - // expects that the lead character is a '"' - for i := 1; i < len(json); i++ { - if json[i] > '\\' { - continue - } - if json[i] == '"' { - return json[:i+1], json[1:i] - } - if json[i] == '\\' { - i++ - for ; i < len(json); i++ { - if json[i] > '\\' { - continue - } - if json[i] == '"' { - // look for an escaped slash - if json[i-1] == '\\' { - n := 0 - for j := i - 2; j > 0; j-- { - if json[j] != '\\' { - break - } - n++ - } - if n%2 == 0 { - continue - } - } - break - } - } - var ret string - if i+1 < len(json) { - ret = json[:i+1] - } else { - ret = json[:i] - } - return ret, unescape(json[1:i]) - } - } - return json, json[1:] -} - -// Exists returns true if value exists. -// -// if gjson.Get(json, "name.last").Exists(){ -// println("value exists") -// } -func (t Result) Exists() bool { - return t.Type != Null || len(t.Raw) != 0 -} - -// Value returns one of these types: -// -// bool, for JSON booleans -// float64, for JSON numbers -// Number, for JSON numbers -// string, for JSON string literals -// nil, for JSON null -// map[string]interface{}, for JSON objects -// []interface{}, for JSON arrays -// -func (t Result) Value() interface{} { - if t.Type == String { - return t.Str - } - switch t.Type { - default: - return nil - case False: - return false - case Number: - return t.Num - case JSON: - r := t.arrayOrMap(0, true) - if r.vc == '{' { - return r.oi - } else if r.vc == '[' { - return r.ai - } - return nil - case True: - return true - } -} - -func parseString(json string, i int) (int, string, bool, bool) { - var s = i - for ; i < len(json); i++ { - if json[i] > '\\' { - continue - } - if json[i] == '"' { - return i + 1, json[s-1 : i+1], false, true - } - if json[i] == '\\' { - i++ - for ; i < len(json); i++ { - if json[i] > '\\' { - continue - } - if json[i] == '"' { - // look for an escaped slash - if json[i-1] == '\\' { - n := 0 - for j := i - 2; j > 0; j-- { - if json[j] != '\\' { - break - } - n++ - } - if n%2 == 0 { - continue - } - } - return i + 1, json[s-1 : i+1], true, true - } - } - break - } - } - return i, json[s-1:], false, false -} - -func parseNumber(json string, i int) (int, string) { - var s = i - i++ - for ; i < len(json); i++ { - if json[i] <= ' ' || json[i] == ',' || json[i] == ']' || - json[i] == '}' { - return i, json[s:i] - } - } - return i, json[s:] -} - -func parseLiteral(json string, i int) (int, string) { - var s = i - i++ - for ; i < len(json); i++ { - if json[i] < 'a' || json[i] > 'z' { - return i, json[s:i] - } - } - return i, json[s:] -} - -type arrayPathResult struct { - part string - path string - pipe string - piped bool - more bool - alogok bool - arrch bool - alogkey string - query struct { - on bool - path string - op string - value string - all bool - } -} - -func parseArrayPath(path string) (r arrayPathResult) { - for i := 0; i < len(path); i++ { - if path[i] == '|' { - r.part = path[:i] - r.pipe = path[i+1:] - r.piped = true - return - } - if path[i] == '.' { - r.part = path[:i] - r.path = path[i+1:] - r.more = true - return - } - if path[i] == '#' { - r.arrch = true - if i == 0 && len(path) > 1 { - if path[1] == '.' { - r.alogok = true - r.alogkey = path[2:] - r.path = path[:1] - } else if path[1] == '[' || path[1] == '(' { - // query - r.query.on = true - if true { - qpath, op, value, _, fi, ok := parseQuery(path[i:]) - if !ok { - // bad query, end now - break - } - r.query.path = qpath - r.query.op = op - r.query.value = value - i = fi - 1 - if i+1 < len(path) && path[i+1] == '#' { - r.query.all = true - } - } else { - var end byte - if path[1] == '[' { - end = ']' - } else { - end = ')' - } - i += 2 - // whitespace - for ; i < len(path); i++ { - if path[i] > ' ' { - break - } - } - s := i - for ; i < len(path); i++ { - if path[i] <= ' ' || - path[i] == '!' || - path[i] == '=' || - path[i] == '<' || - path[i] == '>' || - path[i] == '%' || - path[i] == end { - break - } - } - r.query.path = path[s:i] - // whitespace - for ; i < len(path); i++ { - if path[i] > ' ' { - break - } - } - if i < len(path) { - s = i - if path[i] == '!' { - if i < len(path)-1 && (path[i+1] == '=' || - path[i+1] == '%') { - i++ - } - } else if path[i] == '<' || path[i] == '>' { - if i < len(path)-1 && path[i+1] == '=' { - i++ - } - } else if path[i] == '=' { - if i < len(path)-1 && path[i+1] == '=' { - s++ - i++ - } - } - i++ - r.query.op = path[s:i] - // whitespace - for ; i < len(path); i++ { - if path[i] > ' ' { - break - } - } - s = i - for ; i < len(path); i++ { - if path[i] == '"' { - i++ - s2 := i - for ; i < len(path); i++ { - if path[i] > '\\' { - continue - } - if path[i] == '"' { - // look for an escaped slash - if path[i-1] == '\\' { - n := 0 - for j := i - 2; j > s2-1; j-- { - if path[j] != '\\' { - break - } - n++ - } - if n%2 == 0 { - continue - } - } - break - } - } - } else if path[i] == end { - if i+1 < len(path) && path[i+1] == '#' { - r.query.all = true - } - break - } - } - if i > len(path) { - i = len(path) - } - v := path[s:i] - for len(v) > 0 && v[len(v)-1] <= ' ' { - v = v[:len(v)-1] - } - r.query.value = v - } - } - } - } - continue - } - } - r.part = path - r.path = "" - return -} - -// splitQuery takes a query and splits it into three parts: -// path, op, middle, and right. -// So for this query: -// #(first_name=="Murphy").last -// Becomes -// first_name # path -// =="Murphy" # middle -// .last # right -// Or, -// #(service_roles.#(=="one")).cap -// Becomes -// service_roles.#(=="one") # path -// # middle -// .cap # right -func parseQuery(query string) ( - path, op, value, remain string, i int, ok bool, -) { - if len(query) < 2 || query[0] != '#' || - (query[1] != '(' && query[1] != '[') { - return "", "", "", "", i, false - } - i = 2 - j := 0 // start of value part - depth := 1 - for ; i < len(query); i++ { - if depth == 1 && j == 0 { - switch query[i] { - case '!', '=', '<', '>', '%': - // start of the value part - j = i - continue - } - } - if query[i] == '\\' { - i++ - } else if query[i] == '[' || query[i] == '(' { - depth++ - } else if query[i] == ']' || query[i] == ')' { - depth-- - if depth == 0 { - break - } - } else if query[i] == '"' { - // inside selector string, balance quotes - i++ - for ; i < len(query); i++ { - if query[i] == '\\' { - i++ - } else if query[i] == '"' { - break - } - } - } - } - if depth > 0 { - return "", "", "", "", i, false - } - if j > 0 { - path = trim(query[2:j]) - value = trim(query[j:i]) - remain = query[i+1:] - // parse the compare op from the value - var opsz int - switch { - case len(value) == 1: - opsz = 1 - case value[0] == '!' && value[1] == '=': - opsz = 2 - case value[0] == '!' && value[1] == '%': - opsz = 2 - case value[0] == '<' && value[1] == '=': - opsz = 2 - case value[0] == '>' && value[1] == '=': - opsz = 2 - case value[0] == '=' && value[1] == '=': - value = value[1:] - opsz = 1 - case value[0] == '<': - opsz = 1 - case value[0] == '>': - opsz = 1 - case value[0] == '=': - opsz = 1 - case value[0] == '%': - opsz = 1 - } - op = value[:opsz] - value = trim(value[opsz:]) - } else { - path = trim(query[2:i]) - remain = query[i+1:] - } - return path, op, value, remain, i + 1, true -} - -func trim(s string) string { -left: - if len(s) > 0 && s[0] <= ' ' { - s = s[1:] - goto left - } -right: - if len(s) > 0 && s[len(s)-1] <= ' ' { - s = s[:len(s)-1] - goto right - } - return s -} - -type objectPathResult struct { - part string - path string - pipe string - piped bool - wild bool - more bool -} - -func parseObjectPath(path string) (r objectPathResult) { - for i := 0; i < len(path); i++ { - if path[i] == '|' { - r.part = path[:i] - r.pipe = path[i+1:] - r.piped = true - return - } - if path[i] == '.' { - // peek at the next byte and see if it's a '@', '[', or '{'. - r.part = path[:i] - if !DisableModifiers && - i < len(path)-1 && - (path[i+1] == '@' || - path[i+1] == '[' || path[i+1] == '{') { - r.pipe = path[i+1:] - r.piped = true - } else { - r.path = path[i+1:] - r.more = true - } - return - } - if path[i] == '*' || path[i] == '?' { - r.wild = true - continue - } - if path[i] == '\\' { - // go into escape mode. this is a slower path that - // strips off the escape character from the part. - epart := []byte(path[:i]) - i++ - if i < len(path) { - epart = append(epart, path[i]) - i++ - for ; i < len(path); i++ { - if path[i] == '\\' { - i++ - if i < len(path) { - epart = append(epart, path[i]) - } - continue - } else if path[i] == '.' { - r.part = string(epart) - // peek at the next byte and see if it's a '@' modifier - if !DisableModifiers && - i < len(path)-1 && path[i+1] == '@' { - r.pipe = path[i+1:] - r.piped = true - } else { - r.path = path[i+1:] - r.more = true - } - r.more = true - return - } else if path[i] == '|' { - r.part = string(epart) - r.pipe = path[i+1:] - r.piped = true - return - } else if path[i] == '*' || path[i] == '?' { - r.wild = true - } - epart = append(epart, path[i]) - } - } - // append the last part - r.part = string(epart) - return - } - } - r.part = path - return -} - -func parseSquash(json string, i int) (int, string) { - // expects that the lead character is a '[' or '{' or '(' - // squash the value, ignoring all nested arrays and objects. - // the first '[' or '{' or '(' has already been read - s := i - i++ - depth := 1 - for ; i < len(json); i++ { - if json[i] >= '"' && json[i] <= '}' { - switch json[i] { - case '"': - i++ - s2 := i - for ; i < len(json); i++ { - if json[i] > '\\' { - continue - } - if json[i] == '"' { - // look for an escaped slash - if json[i-1] == '\\' { - n := 0 - for j := i - 2; j > s2-1; j-- { - if json[j] != '\\' { - break - } - n++ - } - if n%2 == 0 { - continue - } - } - break - } - } - case '{', '[', '(': - depth++ - case '}', ']', ')': - depth-- - if depth == 0 { - i++ - return i, json[s:i] - } - } - } - } - return i, json[s:] -} - -func parseObject(c *parseContext, i int, path string) (int, bool) { - var pmatch, kesc, vesc, ok, hit bool - var key, val string - rp := parseObjectPath(path) - if !rp.more && rp.piped { - c.pipe = rp.pipe - c.piped = true - } - for i < len(c.json) { - for ; i < len(c.json); i++ { - if c.json[i] == '"' { - // parse_key_string - // this is slightly different from getting s string value - // because we don't need the outer quotes. - i++ - var s = i - for ; i < len(c.json); i++ { - if c.json[i] > '\\' { - continue - } - if c.json[i] == '"' { - i, key, kesc, ok = i+1, c.json[s:i], false, true - goto parse_key_string_done - } - if c.json[i] == '\\' { - i++ - for ; i < len(c.json); i++ { - if c.json[i] > '\\' { - continue - } - if c.json[i] == '"' { - // look for an escaped slash - if c.json[i-1] == '\\' { - n := 0 - for j := i - 2; j > 0; j-- { - if c.json[j] != '\\' { - break - } - n++ - } - if n%2 == 0 { - continue - } - } - i, key, kesc, ok = i+1, c.json[s:i], true, true - goto parse_key_string_done - } - } - break - } - } - key, kesc, ok = c.json[s:], false, false - parse_key_string_done: - break - } - if c.json[i] == '}' { - return i + 1, false - } - } - if !ok { - return i, false - } - if rp.wild { - if kesc { - pmatch = match.Match(unescape(key), rp.part) - } else { - pmatch = match.Match(key, rp.part) - } - } else { - if kesc { - pmatch = rp.part == unescape(key) - } else { - pmatch = rp.part == key - } - } - hit = pmatch && !rp.more - for ; i < len(c.json); i++ { - switch c.json[i] { - default: - continue - case '"': - i++ - i, val, vesc, ok = parseString(c.json, i) - if !ok { - return i, false - } - if hit { - if vesc { - c.value.Str = unescape(val[1 : len(val)-1]) - } else { - c.value.Str = val[1 : len(val)-1] - } - c.value.Raw = val - c.value.Type = String - return i, true - } - case '{': - if pmatch && !hit { - i, hit = parseObject(c, i+1, rp.path) - if hit { - return i, true - } - } else { - i, val = parseSquash(c.json, i) - if hit { - c.value.Raw = val - c.value.Type = JSON - return i, true - } - } - case '[': - if pmatch && !hit { - i, hit = parseArray(c, i+1, rp.path) - if hit { - return i, true - } - } else { - i, val = parseSquash(c.json, i) - if hit { - c.value.Raw = val - c.value.Type = JSON - return i, true - } - } - case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': - i, val = parseNumber(c.json, i) - if hit { - c.value.Raw = val - c.value.Type = Number - c.value.Num, _ = strconv.ParseFloat(val, 64) - return i, true - } - case 't', 'f', 'n': - vc := c.json[i] - i, val = parseLiteral(c.json, i) - if hit { - c.value.Raw = val - switch vc { - case 't': - c.value.Type = True - case 'f': - c.value.Type = False - } - return i, true - } - } - break - } - } - return i, false -} -func queryMatches(rp *arrayPathResult, value Result) bool { - rpv := rp.query.value - if len(rpv) > 2 && rpv[0] == '"' && rpv[len(rpv)-1] == '"' { - rpv = rpv[1 : len(rpv)-1] - } - if !value.Exists() { - return false - } - if rp.query.op == "" { - // the query is only looking for existence, such as: - // friends.#(name) - // which makes sure that the array "friends" has an element of - // "name" that exists - return true - } - switch value.Type { - case String: - switch rp.query.op { - case "=": - return value.Str == rpv - case "!=": - return value.Str != rpv - case "<": - return value.Str < rpv - case "<=": - return value.Str <= rpv - case ">": - return value.Str > rpv - case ">=": - return value.Str >= rpv - case "%": - return match.Match(value.Str, rpv) - case "!%": - return !match.Match(value.Str, rpv) - } - case Number: - rpvn, _ := strconv.ParseFloat(rpv, 64) - switch rp.query.op { - case "=": - return value.Num == rpvn - case "!=": - return value.Num != rpvn - case "<": - return value.Num < rpvn - case "<=": - return value.Num <= rpvn - case ">": - return value.Num > rpvn - case ">=": - return value.Num >= rpvn - } - case True: - switch rp.query.op { - case "=": - return rpv == "true" - case "!=": - return rpv != "true" - case ">": - return rpv == "false" - case ">=": - return true - } - case False: - switch rp.query.op { - case "=": - return rpv == "false" - case "!=": - return rpv != "false" - case "<": - return rpv == "true" - case "<=": - return true - } - } - return false -} -func parseArray(c *parseContext, i int, path string) (int, bool) { - var pmatch, vesc, ok, hit bool - var val string - var h int - var alog []int - var partidx int - var multires []byte - rp := parseArrayPath(path) - if !rp.arrch { - n, ok := parseUint(rp.part) - if !ok { - partidx = -1 - } else { - partidx = int(n) - } - } - if !rp.more && rp.piped { - c.pipe = rp.pipe - c.piped = true - } - - procQuery := func(qval Result) bool { - if rp.query.all { - if len(multires) == 0 { - multires = append(multires, '[') - } - } - var res Result - if qval.Type == JSON { - res = qval.Get(rp.query.path) - } else { - if rp.query.path != "" { - return false - } - res = qval - } - if queryMatches(&rp, res) { - if rp.more { - left, right, ok := splitPossiblePipe(rp.path) - if ok { - rp.path = left - c.pipe = right - c.piped = true - } - res = qval.Get(rp.path) - } else { - res = qval - } - if rp.query.all { - raw := res.Raw - if len(raw) == 0 { - raw = res.String() - } - if raw != "" { - if len(multires) > 1 { - multires = append(multires, ',') - } - multires = append(multires, raw...) - } - } else { - c.value = res - return true - } - } - return false - } - - for i < len(c.json)+1 { - if !rp.arrch { - pmatch = partidx == h - hit = pmatch && !rp.more - } - h++ - if rp.alogok { - alog = append(alog, i) - } - for ; ; i++ { - var ch byte - if i > len(c.json) { - break - } else if i == len(c.json) { - ch = ']' - } else { - ch = c.json[i] - } - switch ch { - default: - continue - case '"': - i++ - i, val, vesc, ok = parseString(c.json, i) - if !ok { - return i, false - } - if rp.query.on { - var qval Result - if vesc { - qval.Str = unescape(val[1 : len(val)-1]) - } else { - qval.Str = val[1 : len(val)-1] - } - qval.Raw = val - qval.Type = String - if procQuery(qval) { - return i, true - } - } else if hit { - if rp.alogok { - break - } - if vesc { - c.value.Str = unescape(val[1 : len(val)-1]) - } else { - c.value.Str = val[1 : len(val)-1] - } - c.value.Raw = val - c.value.Type = String - return i, true - } - case '{': - if pmatch && !hit { - i, hit = parseObject(c, i+1, rp.path) - if hit { - if rp.alogok { - break - } - return i, true - } - } else { - i, val = parseSquash(c.json, i) - if rp.query.on { - if procQuery(Result{Raw: val, Type: JSON}) { - return i, true - } - } else if hit { - if rp.alogok { - break - } - c.value.Raw = val - c.value.Type = JSON - return i, true - } - } - case '[': - if pmatch && !hit { - i, hit = parseArray(c, i+1, rp.path) - if hit { - if rp.alogok { - break - } - return i, true - } - } else { - i, val = parseSquash(c.json, i) - if rp.query.on { - if procQuery(Result{Raw: val, Type: JSON}) { - return i, true - } - } else if hit { - if rp.alogok { - break - } - c.value.Raw = val - c.value.Type = JSON - return i, true - } - } - case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': - i, val = parseNumber(c.json, i) - if rp.query.on { - var qval Result - qval.Raw = val - qval.Type = Number - qval.Num, _ = strconv.ParseFloat(val, 64) - if procQuery(qval) { - return i, true - } - } else if hit { - if rp.alogok { - break - } - c.value.Raw = val - c.value.Type = Number - c.value.Num, _ = strconv.ParseFloat(val, 64) - return i, true - } - case 't', 'f', 'n': - vc := c.json[i] - i, val = parseLiteral(c.json, i) - if rp.query.on { - var qval Result - qval.Raw = val - switch vc { - case 't': - qval.Type = True - case 'f': - qval.Type = False - } - if procQuery(qval) { - return i, true - } - } else if hit { - if rp.alogok { - break - } - c.value.Raw = val - switch vc { - case 't': - c.value.Type = True - case 'f': - c.value.Type = False - } - return i, true - } - case ']': - if rp.arrch && rp.part == "#" { - if rp.alogok { - left, right, ok := splitPossiblePipe(rp.alogkey) - if ok { - rp.alogkey = left - c.pipe = right - c.piped = true - } - var jsons = make([]byte, 0, 64) - jsons = append(jsons, '[') - for j, k := 0, 0; j < len(alog); j++ { - idx := alog[j] - for idx < len(c.json) { - switch c.json[idx] { - case ' ', '\t', '\r', '\n': - idx++ - continue - } - break - } - if idx < len(c.json) && c.json[idx] != ']' { - _, res, ok := parseAny(c.json, idx, true) - if ok { - res := res.Get(rp.alogkey) - if res.Exists() { - if k > 0 { - jsons = append(jsons, ',') - } - raw := res.Raw - if len(raw) == 0 { - raw = res.String() - } - jsons = append(jsons, []byte(raw)...) - k++ - } - } - } - } - jsons = append(jsons, ']') - c.value.Type = JSON - c.value.Raw = string(jsons) - return i + 1, true - } - if rp.alogok { - break - } - - c.value.Type = Number - c.value.Num = float64(h - 1) - c.value.Raw = strconv.Itoa(h - 1) - c.calcd = true - return i + 1, true - } - if len(multires) > 0 && !c.value.Exists() { - c.value = Result{ - Raw: string(append(multires, ']')), - Type: JSON, - } - } - return i + 1, false - } - break - } - } - return i, false -} - -func splitPossiblePipe(path string) (left, right string, ok bool) { - // take a quick peek for the pipe character. If found we'll split the piped - // part of the path into the c.pipe field and shorten the rp. - var possible bool - for i := 0; i < len(path); i++ { - if path[i] == '|' { - possible = true - break - } - } - if !possible { - return - } - - if len(path) > 0 && path[0] == '{' { - squashed := squash(path[1:]) - if len(squashed) < len(path)-1 { - squashed = path[:len(squashed)+1] - remain := path[len(squashed):] - if remain[0] == '|' { - return squashed, remain[1:], true - } - } - return - } - - // split the left and right side of the path with the pipe character as - // the delimiter. This is a little tricky because we'll need to basically - // parse the entire path. - for i := 0; i < len(path); i++ { - if path[i] == '\\' { - i++ - } else if path[i] == '.' { - if i == len(path)-1 { - return - } - if path[i+1] == '#' { - i += 2 - if i == len(path) { - return - } - if path[i] == '[' || path[i] == '(' { - var start, end byte - if path[i] == '[' { - start, end = '[', ']' - } else { - start, end = '(', ')' - } - // inside selector, balance brackets - i++ - depth := 1 - for ; i < len(path); i++ { - if path[i] == '\\' { - i++ - } else if path[i] == start { - depth++ - } else if path[i] == end { - depth-- - if depth == 0 { - break - } - } else if path[i] == '"' { - // inside selector string, balance quotes - i++ - for ; i < len(path); i++ { - if path[i] == '\\' { - i++ - } else if path[i] == '"' { - break - } - } - } - } - } - } - } else if path[i] == '|' { - return path[:i], path[i+1:], true - } - } - return -} - -// ForEachLine iterates through lines of JSON as specified by the JSON Lines -// format (http://jsonlines.org/). -// Each line is returned as a GJSON Result. -func ForEachLine(json string, iterator func(line Result) bool) { - var res Result - var i int - for { - i, res, _ = parseAny(json, i, true) - if !res.Exists() { - break - } - if !iterator(res) { - return - } - } -} - -type subSelector struct { - name string - path string -} - -// parseSubSelectors returns the subselectors belonging to a '[path1,path2]' or -// '{"field1":path1,"field2":path2}' type subSelection. It's expected that the -// first character in path is either '[' or '{', and has already been checked -// prior to calling this function. -func parseSubSelectors(path string) (sels []subSelector, out string, ok bool) { - modifer := 0 - depth := 1 - colon := 0 - start := 1 - i := 1 - pushSel := func() { - var sel subSelector - if colon == 0 { - sel.path = path[start:i] - } else { - sel.name = path[start:colon] - sel.path = path[colon+1 : i] - } - sels = append(sels, sel) - colon = 0 - start = i + 1 - } - for ; i < len(path); i++ { - switch path[i] { - case '\\': - i++ - case '@': - if modifer == 0 && i > 0 && (path[i-1] == '.' || path[i-1] == '|') { - modifer = i - } - case ':': - if modifer == 0 && colon == 0 && depth == 1 { - colon = i - } - case ',': - if depth == 1 { - pushSel() - } - case '"': - i++ - loop: - for ; i < len(path); i++ { - switch path[i] { - case '\\': - i++ - case '"': - break loop - } - } - case '[', '(', '{': - depth++ - case ']', ')', '}': - depth-- - if depth == 0 { - pushSel() - path = path[i+1:] - return sels, path, true - } - } - } - return -} - -// nameOfLast returns the name of the last component -func nameOfLast(path string) string { - for i := len(path) - 1; i >= 0; i-- { - if path[i] == '|' || path[i] == '.' { - if i > 0 { - if path[i-1] == '\\' { - continue - } - } - return path[i+1:] - } - } - return path -} - -func isSimpleName(component string) bool { - for i := 0; i < len(component); i++ { - if component[i] < ' ' { - return false - } - switch component[i] { - case '[', ']', '{', '}', '(', ')', '#', '|': - return false - } - } - return true -} - -func appendJSONString(dst []byte, s string) []byte { - for i := 0; i < len(s); i++ { - if s[i] < ' ' || s[i] == '\\' || s[i] == '"' || s[i] > 126 { - d, _ := json.Marshal(s) - return append(dst, string(d)...) - } - } - dst = append(dst, '"') - dst = append(dst, s...) - dst = append(dst, '"') - return dst -} - -type parseContext struct { - json string - value Result - pipe string - piped bool - calcd bool - lines bool -} - -// Get searches json for the specified path. -// A path is in dot syntax, such as "name.last" or "age". -// When the value is found it's returned immediately. -// -// A path is a series of keys searated by a dot. -// A key may contain special wildcard characters '*' and '?'. -// To access an array value use the index as the key. -// To get the number of elements in an array or to access a child path, use -// the '#' character. -// The dot and wildcard character can be escaped with '\'. -// -// { -// "name": {"first": "Tom", "last": "Anderson"}, -// "age":37, -// "children": ["Sara","Alex","Jack"], -// "friends": [ -// {"first": "James", "last": "Murphy"}, -// {"first": "Roger", "last": "Craig"} -// ] -// } -// "name.last" >> "Anderson" -// "age" >> 37 -// "children" >> ["Sara","Alex","Jack"] -// "children.#" >> 3 -// "children.1" >> "Alex" -// "child*.2" >> "Jack" -// "c?ildren.0" >> "Sara" -// "friends.#.first" >> ["James","Roger"] -// -// This function expects that the json is well-formed, and does not validate. -// Invalid json will not panic, but it may return back unexpected results. -// If you are consuming JSON from an unpredictable source then you may want to -// use the Valid function first. -func Get(json, path string) Result { - if len(path) > 1 { - if !DisableModifiers { - if path[0] == '@' { - // possible modifier - var ok bool - var npath string - var rjson string - npath, rjson, ok = execModifier(json, path) - if ok { - path = npath - if len(path) > 0 && (path[0] == '|' || path[0] == '.') { - res := Get(rjson, path[1:]) - res.Index = 0 - return res - } - return Parse(rjson) - } - } - } - if path[0] == '[' || path[0] == '{' { - // using a subselector path - kind := path[0] - var ok bool - var subs []subSelector - subs, path, ok = parseSubSelectors(path) - if ok { - if len(path) == 0 || (path[0] == '|' || path[0] == '.') { - var b []byte - b = append(b, kind) - var i int - for _, sub := range subs { - res := Get(json, sub.path) - if res.Exists() { - if i > 0 { - b = append(b, ',') - } - if kind == '{' { - if len(sub.name) > 0 { - if sub.name[0] == '"' && Valid(sub.name) { - b = append(b, sub.name...) - } else { - b = appendJSONString(b, sub.name) - } - } else { - last := nameOfLast(sub.path) - if isSimpleName(last) { - b = appendJSONString(b, last) - } else { - b = appendJSONString(b, "_") - } - } - b = append(b, ':') - } - var raw string - if len(res.Raw) == 0 { - raw = res.String() - if len(raw) == 0 { - raw = "null" - } - } else { - raw = res.Raw - } - b = append(b, raw...) - i++ - } - } - b = append(b, kind+2) - var res Result - res.Raw = string(b) - res.Type = JSON - if len(path) > 0 { - res = res.Get(path[1:]) - } - res.Index = 0 - return res - } - } - } - } - - var i int - var c = &parseContext{json: json} - if len(path) >= 2 && path[0] == '.' && path[1] == '.' { - c.lines = true - parseArray(c, 0, path[2:]) - } else { - for ; i < len(c.json); i++ { - if c.json[i] == '{' { - i++ - parseObject(c, i, path) - break - } - if c.json[i] == '[' { - i++ - parseArray(c, i, path) - break - } - } - } - if c.piped { - res := c.value.Get(c.pipe) - res.Index = 0 - return res - } - fillIndex(json, c) - return c.value -} - -// GetBytes searches json for the specified path. -// If working with bytes, this method preferred over Get(string(data), path) -func GetBytes(json []byte, path string) Result { - return getBytes(json, path) -} - -// runeit returns the rune from the the \uXXXX -func runeit(json string) rune { - n, _ := strconv.ParseUint(json[:4], 16, 64) - return rune(n) -} - -// unescape unescapes a string -func unescape(json string) string { //, error) { - var str = make([]byte, 0, len(json)) - for i := 0; i < len(json); i++ { - switch { - default: - str = append(str, json[i]) - case json[i] < ' ': - return string(str) - case json[i] == '\\': - i++ - if i >= len(json) { - return string(str) - } - switch json[i] { - default: - return string(str) - case '\\': - str = append(str, '\\') - case '/': - str = append(str, '/') - case 'b': - str = append(str, '\b') - case 'f': - str = append(str, '\f') - case 'n': - str = append(str, '\n') - case 'r': - str = append(str, '\r') - case 't': - str = append(str, '\t') - case '"': - str = append(str, '"') - case 'u': - if i+5 > len(json) { - return string(str) - } - r := runeit(json[i+1:]) - i += 5 - if utf16.IsSurrogate(r) { - // need another code - if len(json[i:]) >= 6 && json[i] == '\\' && - json[i+1] == 'u' { - // we expect it to be correct so just consume it - r = utf16.DecodeRune(r, runeit(json[i+2:])) - i += 6 - } - } - // provide enough space to encode the largest utf8 possible - str = append(str, 0, 0, 0, 0, 0, 0, 0, 0) - n := utf8.EncodeRune(str[len(str)-8:], r) - str = str[:len(str)-8+n] - i-- // backtrack index by one - } - } - } - return string(str) -} - -// Less return true if a token is less than another token. -// The caseSensitive paramater is used when the tokens are Strings. -// The order when comparing two different type is: -// -// Null < False < Number < String < True < JSON -// -func (t Result) Less(token Result, caseSensitive bool) bool { - if t.Type < token.Type { - return true - } - if t.Type > token.Type { - return false - } - if t.Type == String { - if caseSensitive { - return t.Str < token.Str - } - return stringLessInsensitive(t.Str, token.Str) - } - if t.Type == Number { - return t.Num < token.Num - } - return t.Raw < token.Raw -} - -func stringLessInsensitive(a, b string) bool { - for i := 0; i < len(a) && i < len(b); i++ { - if a[i] >= 'A' && a[i] <= 'Z' { - if b[i] >= 'A' && b[i] <= 'Z' { - // both are uppercase, do nothing - if a[i] < b[i] { - return true - } else if a[i] > b[i] { - return false - } - } else { - // a is uppercase, convert a to lowercase - if a[i]+32 < b[i] { - return true - } else if a[i]+32 > b[i] { - return false - } - } - } else if b[i] >= 'A' && b[i] <= 'Z' { - // b is uppercase, convert b to lowercase - if a[i] < b[i]+32 { - return true - } else if a[i] > b[i]+32 { - return false - } - } else { - // neither are uppercase - if a[i] < b[i] { - return true - } else if a[i] > b[i] { - return false - } - } - } - return len(a) < len(b) -} - -// parseAny parses the next value from a json string. -// A Result is returned when the hit param is set. -// The return values are (i int, res Result, ok bool) -func parseAny(json string, i int, hit bool) (int, Result, bool) { - var res Result - var val string - for ; i < len(json); i++ { - if json[i] == '{' || json[i] == '[' { - i, val = parseSquash(json, i) - if hit { - res.Raw = val - res.Type = JSON - } - return i, res, true - } - if json[i] <= ' ' { - continue - } - switch json[i] { - case '"': - i++ - var vesc bool - var ok bool - i, val, vesc, ok = parseString(json, i) - if !ok { - return i, res, false - } - if hit { - res.Type = String - res.Raw = val - if vesc { - res.Str = unescape(val[1 : len(val)-1]) - } else { - res.Str = val[1 : len(val)-1] - } - } - return i, res, true - case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': - i, val = parseNumber(json, i) - if hit { - res.Raw = val - res.Type = Number - res.Num, _ = strconv.ParseFloat(val, 64) - } - return i, res, true - case 't', 'f', 'n': - vc := json[i] - i, val = parseLiteral(json, i) - if hit { - res.Raw = val - switch vc { - case 't': - res.Type = True - case 'f': - res.Type = False - } - return i, res, true - } - } - } - return i, res, false -} - -var ( // used for testing - testWatchForFallback bool - testLastWasFallback bool -) - -// GetMany searches json for the multiple paths. -// The return value is a Result array where the number of items -// will be equal to the number of input paths. -func GetMany(json string, path ...string) []Result { - res := make([]Result, len(path)) - for i, path := range path { - res[i] = Get(json, path) - } - return res -} - -// GetManyBytes searches json for the multiple paths. -// The return value is a Result array where the number of items -// will be equal to the number of input paths. -func GetManyBytes(json []byte, path ...string) []Result { - res := make([]Result, len(path)) - for i, path := range path { - res[i] = GetBytes(json, path) - } - return res -} - -var fieldsmu sync.RWMutex -var fields = make(map[string]map[string]int) - -func assign(jsval Result, goval reflect.Value) { - if jsval.Type == Null { - return - } - switch goval.Kind() { - default: - case reflect.Ptr: - if !goval.IsNil() { - newval := reflect.New(goval.Elem().Type()) - assign(jsval, newval.Elem()) - goval.Elem().Set(newval.Elem()) - } else { - newval := reflect.New(goval.Type().Elem()) - assign(jsval, newval.Elem()) - goval.Set(newval) - } - case reflect.Struct: - fieldsmu.RLock() - sf := fields[goval.Type().String()] - fieldsmu.RUnlock() - if sf == nil { - fieldsmu.Lock() - sf = make(map[string]int) - for i := 0; i < goval.Type().NumField(); i++ { - f := goval.Type().Field(i) - tag := strings.Split(f.Tag.Get("json"), ",")[0] - if tag != "-" { - if tag != "" { - sf[tag] = i - sf[f.Name] = i - } else { - sf[f.Name] = i - } - } - } - fields[goval.Type().String()] = sf - fieldsmu.Unlock() - } - jsval.ForEach(func(key, value Result) bool { - if idx, ok := sf[key.Str]; ok { - f := goval.Field(idx) - if f.CanSet() { - assign(value, f) - } - } - return true - }) - case reflect.Slice: - if goval.Type().Elem().Kind() == reflect.Uint8 && - jsval.Type == String { - data, _ := base64.StdEncoding.DecodeString(jsval.String()) - goval.Set(reflect.ValueOf(data)) - } else { - jsvals := jsval.Array() - slice := reflect.MakeSlice(goval.Type(), len(jsvals), len(jsvals)) - for i := 0; i < len(jsvals); i++ { - assign(jsvals[i], slice.Index(i)) - } - goval.Set(slice) - } - case reflect.Array: - i, n := 0, goval.Len() - jsval.ForEach(func(_, value Result) bool { - if i == n { - return false - } - assign(value, goval.Index(i)) - i++ - return true - }) - case reflect.Map: - if goval.Type().Key().Kind() == reflect.String && - goval.Type().Elem().Kind() == reflect.Interface { - goval.Set(reflect.ValueOf(jsval.Value())) - } - case reflect.Interface: - goval.Set(reflect.ValueOf(jsval.Value())) - case reflect.Bool: - goval.SetBool(jsval.Bool()) - case reflect.Float32, reflect.Float64: - goval.SetFloat(jsval.Float()) - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, - reflect.Int64: - goval.SetInt(jsval.Int()) - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, - reflect.Uint64: - goval.SetUint(jsval.Uint()) - case reflect.String: - goval.SetString(jsval.String()) - } - if len(goval.Type().PkgPath()) > 0 { - v := goval.Addr() - if v.Type().NumMethod() > 0 { - if u, ok := v.Interface().(json.Unmarshaler); ok { - u.UnmarshalJSON([]byte(jsval.Raw)) - } - } - } -} - -var validate uintptr = 1 - -// UnmarshalValidationEnabled provides the option to disable JSON validation -// during the Unmarshal routine. Validation is enabled by default. -// -// Deprecated: Use encoder/json.Unmarshal instead -func UnmarshalValidationEnabled(enabled bool) { - if enabled { - atomic.StoreUintptr(&validate, 1) - } else { - atomic.StoreUintptr(&validate, 0) - } -} - -// Unmarshal loads the JSON data into the value pointed to by v. -// -// This function works almost identically to json.Unmarshal except that -// gjson.Unmarshal will automatically attempt to convert JSON values to any Go -// type. For example, the JSON string "100" or the JSON number 100 can be -// equally assigned to Go string, int, byte, uint64, etc. This rule applies to -// all types. -// -// Deprecated: Use encoder/json.Unmarshal instead -func Unmarshal(data []byte, v interface{}) error { - if atomic.LoadUintptr(&validate) == 1 { - _, ok := validpayload(data, 0) - if !ok { - return errors.New("invalid json") - } - } - if v := reflect.ValueOf(v); v.Kind() == reflect.Ptr { - assign(ParseBytes(data), v) - } - return nil -} - -func validpayload(data []byte, i int) (outi int, ok bool) { - for ; i < len(data); i++ { - switch data[i] { - default: - i, ok = validany(data, i) - if !ok { - return i, false - } - for ; i < len(data); i++ { - switch data[i] { - default: - return i, false - case ' ', '\t', '\n', '\r': - continue - } - } - return i, true - case ' ', '\t', '\n', '\r': - continue - } - } - return i, false -} -func validany(data []byte, i int) (outi int, ok bool) { - for ; i < len(data); i++ { - switch data[i] { - default: - return i, false - case ' ', '\t', '\n', '\r': - continue - case '{': - return validobject(data, i+1) - case '[': - return validarray(data, i+1) - case '"': - return validstring(data, i+1) - case '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9': - return validnumber(data, i+1) - case 't': - return validtrue(data, i+1) - case 'f': - return validfalse(data, i+1) - case 'n': - return validnull(data, i+1) - } - } - return i, false -} -func validobject(data []byte, i int) (outi int, ok bool) { - for ; i < len(data); i++ { - switch data[i] { - default: - return i, false - case ' ', '\t', '\n', '\r': - continue - case '}': - return i + 1, true - case '"': - key: - if i, ok = validstring(data, i+1); !ok { - return i, false - } - if i, ok = validcolon(data, i); !ok { - return i, false - } - if i, ok = validany(data, i); !ok { - return i, false - } - if i, ok = validcomma(data, i, '}'); !ok { - return i, false - } - if data[i] == '}' { - return i + 1, true - } - i++ - for ; i < len(data); i++ { - switch data[i] { - default: - return i, false - case ' ', '\t', '\n', '\r': - continue - case '"': - goto key - } - } - return i, false - } - } - return i, false -} -func validcolon(data []byte, i int) (outi int, ok bool) { - for ; i < len(data); i++ { - switch data[i] { - default: - return i, false - case ' ', '\t', '\n', '\r': - continue - case ':': - return i + 1, true - } - } - return i, false -} -func validcomma(data []byte, i int, end byte) (outi int, ok bool) { - for ; i < len(data); i++ { - switch data[i] { - default: - return i, false - case ' ', '\t', '\n', '\r': - continue - case ',': - return i, true - case end: - return i, true - } - } - return i, false -} -func validarray(data []byte, i int) (outi int, ok bool) { - for ; i < len(data); i++ { - switch data[i] { - default: - for ; i < len(data); i++ { - if i, ok = validany(data, i); !ok { - return i, false - } - if i, ok = validcomma(data, i, ']'); !ok { - return i, false - } - if data[i] == ']' { - return i + 1, true - } - } - case ' ', '\t', '\n', '\r': - continue - case ']': - return i + 1, true - } - } - return i, false -} -func validstring(data []byte, i int) (outi int, ok bool) { - for ; i < len(data); i++ { - if data[i] < ' ' { - return i, false - } else if data[i] == '\\' { - i++ - if i == len(data) { - return i, false - } - switch data[i] { - default: - return i, false - case '"', '\\', '/', 'b', 'f', 'n', 'r', 't': - case 'u': - for j := 0; j < 4; j++ { - i++ - if i >= len(data) { - return i, false - } - if !((data[i] >= '0' && data[i] <= '9') || - (data[i] >= 'a' && data[i] <= 'f') || - (data[i] >= 'A' && data[i] <= 'F')) { - return i, false - } - } - } - } else if data[i] == '"' { - return i + 1, true - } - } - return i, false -} -func validnumber(data []byte, i int) (outi int, ok bool) { - i-- - // sign - if data[i] == '-' { - i++ - } - // int - if i == len(data) { - return i, false - } - if data[i] == '0' { - i++ - } else { - for ; i < len(data); i++ { - if data[i] >= '0' && data[i] <= '9' { - continue - } - break - } - } - // frac - if i == len(data) { - return i, true - } - if data[i] == '.' { - i++ - if i == len(data) { - return i, false - } - if data[i] < '0' || data[i] > '9' { - return i, false - } - i++ - for ; i < len(data); i++ { - if data[i] >= '0' && data[i] <= '9' { - continue - } - break - } - } - // exp - if i == len(data) { - return i, true - } - if data[i] == 'e' || data[i] == 'E' { - i++ - if i == len(data) { - return i, false - } - if data[i] == '+' || data[i] == '-' { - i++ - } - if i == len(data) { - return i, false - } - if data[i] < '0' || data[i] > '9' { - return i, false - } - i++ - for ; i < len(data); i++ { - if data[i] >= '0' && data[i] <= '9' { - continue - } - break - } - } - return i, true -} - -func validtrue(data []byte, i int) (outi int, ok bool) { - if i+3 <= len(data) && data[i] == 'r' && data[i+1] == 'u' && - data[i+2] == 'e' { - return i + 3, true - } - return i, false -} -func validfalse(data []byte, i int) (outi int, ok bool) { - if i+4 <= len(data) && data[i] == 'a' && data[i+1] == 'l' && - data[i+2] == 's' && data[i+3] == 'e' { - return i + 4, true - } - return i, false -} -func validnull(data []byte, i int) (outi int, ok bool) { - if i+3 <= len(data) && data[i] == 'u' && data[i+1] == 'l' && - data[i+2] == 'l' { - return i + 3, true - } - return i, false -} - -// Valid returns true if the input is valid json. -// -// if !gjson.Valid(json) { -// return errors.New("invalid json") -// } -// value := gjson.Get(json, "name.last") -// -func Valid(json string) bool { - _, ok := validpayload(stringBytes(json), 0) - return ok -} - -// ValidBytes returns true if the input is valid json. -// -// if !gjson.Valid(json) { -// return errors.New("invalid json") -// } -// value := gjson.Get(json, "name.last") -// -// If working with bytes, this method preferred over ValidBytes(string(data)) -// -func ValidBytes(json []byte) bool { - _, ok := validpayload(json, 0) - return ok -} - -func parseUint(s string) (n uint64, ok bool) { - var i int - if i == len(s) { - return 0, false - } - for ; i < len(s); i++ { - if s[i] >= '0' && s[i] <= '9' { - n = n*10 + uint64(s[i]-'0') - } else { - return 0, false - } - } - return n, true -} - -func parseInt(s string) (n int64, ok bool) { - var i int - var sign bool - if len(s) > 0 && s[0] == '-' { - sign = true - i++ - } - if i == len(s) { - return 0, false - } - for ; i < len(s); i++ { - if s[i] >= '0' && s[i] <= '9' { - n = n*10 + int64(s[i]-'0') - } else { - return 0, false - } - } - if sign { - return n * -1, true - } - return n, true -} - -const minUint53 = 0 -const maxUint53 = 4503599627370495 -const minInt53 = -2251799813685248 -const maxInt53 = 2251799813685247 - -func floatToUint(f float64) (n uint64, ok bool) { - n = uint64(f) - if float64(n) == f && n >= minUint53 && n <= maxUint53 { - return n, true - } - return 0, false -} - -func floatToInt(f float64) (n int64, ok bool) { - n = int64(f) - if float64(n) == f && n >= minInt53 && n <= maxInt53 { - return n, true - } - return 0, false -} - -// execModifier parses the path to find a matching modifier function. -// then input expects that the path already starts with a '@' -func execModifier(json, path string) (pathOut, res string, ok bool) { - name := path[1:] - var hasArgs bool - for i := 1; i < len(path); i++ { - if path[i] == ':' { - pathOut = path[i+1:] - name = path[1:i] - hasArgs = len(pathOut) > 0 - break - } - if path[i] == '|' { - pathOut = path[i:] - name = path[1:i] - break - } - if path[i] == '.' { - pathOut = path[i:] - name = path[1:i] - break - } - } - if fn, ok := modifiers[name]; ok { - var args string - if hasArgs { - var parsedArgs bool - switch pathOut[0] { - case '{', '[', '"': - res := Parse(pathOut) - if res.Exists() { - _, args = parseSquash(pathOut, 0) - pathOut = pathOut[len(args):] - parsedArgs = true - } - } - if !parsedArgs { - idx := strings.IndexByte(pathOut, '|') - if idx == -1 { - args = pathOut - pathOut = "" - } else { - args = pathOut[:idx] - pathOut = pathOut[idx:] - } - } - } - return pathOut, fn(json, args), true - } - return pathOut, res, false -} - -// DisableModifiers will disable the modifier syntax -var DisableModifiers = false - -var modifiers = map[string]func(json, arg string) string{ - "pretty": modPretty, - "ugly": modUgly, - "reverse": modReverse, -} - -// AddModifier binds a custom modifier command to the GJSON syntax. -// This operation is not thread safe and should be executed prior to -// using all other gjson function. -func AddModifier(name string, fn func(json, arg string) string) { - modifiers[name] = fn -} - -// ModifierExists returns true when the specified modifier exists. -func ModifierExists(name string, fn func(json, arg string) string) bool { - _, ok := modifiers[name] - return ok -} - -// @pretty modifier makes the json look nice. -func modPretty(json, arg string) string { - if len(arg) > 0 { - opts := *pretty.DefaultOptions - Parse(arg).ForEach(func(key, value Result) bool { - switch key.String() { - case "sortKeys": - opts.SortKeys = value.Bool() - case "indent": - opts.Indent = value.String() - case "prefix": - opts.Prefix = value.String() - case "width": - opts.Width = int(value.Int()) - } - return true - }) - return bytesString(pretty.PrettyOptions(stringBytes(json), &opts)) - } - return bytesString(pretty.Pretty(stringBytes(json))) -} - -// @ugly modifier removes all whitespace. -func modUgly(json, arg string) string { - return bytesString(pretty.Ugly(stringBytes(json))) -} - -// @reverse reverses array elements or root object members. -func modReverse(json, arg string) string { - res := Parse(json) - if res.IsArray() { - var values []Result - res.ForEach(func(_, value Result) bool { - values = append(values, value) - return true - }) - out := make([]byte, 0, len(json)) - out = append(out, '[') - for i, j := len(values)-1, 0; i >= 0; i, j = i-1, j+1 { - if j > 0 { - out = append(out, ',') - } - out = append(out, values[i].Raw...) - } - out = append(out, ']') - return bytesString(out) - } - if res.IsObject() { - var keyValues []Result - res.ForEach(func(key, value Result) bool { - keyValues = append(keyValues, key, value) - return true - }) - out := make([]byte, 0, len(json)) - out = append(out, '{') - for i, j := len(keyValues)-2, 0; i >= 0; i, j = i-2, j+1 { - if j > 0 { - out = append(out, ',') - } - out = append(out, keyValues[i+0].Raw...) - out = append(out, ':') - out = append(out, keyValues[i+1].Raw...) - } - out = append(out, '}') - return bytesString(out) - } - return json -} diff --git a/vendor/github.com/tidwall/gjson/gjson_gae.go b/vendor/github.com/tidwall/gjson/gjson_gae.go deleted file mode 100644 index 9586903..0000000 --- a/vendor/github.com/tidwall/gjson/gjson_gae.go +++ /dev/null @@ -1,18 +0,0 @@ -//+build appengine js - -package gjson - -func getBytes(json []byte, path string) Result { - return Get(string(json), path) -} -func fillIndex(json string, c *parseContext) { - // noop. Use zero for the Index value. -} - -func stringBytes(s string) []byte { - return []byte(s) -} - -func bytesString(b []byte) string { - return string(b) -} diff --git a/vendor/github.com/tidwall/gjson/gjson_ngae.go b/vendor/github.com/tidwall/gjson/gjson_ngae.go deleted file mode 100644 index bc608b5..0000000 --- a/vendor/github.com/tidwall/gjson/gjson_ngae.go +++ /dev/null @@ -1,81 +0,0 @@ -//+build !appengine -//+build !js - -package gjson - -import ( - "reflect" - "unsafe" -) - -// getBytes casts the input json bytes to a string and safely returns the -// results as uniquely allocated data. This operation is intended to minimize -// copies and allocations for the large json string->[]byte. -func getBytes(json []byte, path string) Result { - var result Result - if json != nil { - // unsafe cast to string - result = Get(*(*string)(unsafe.Pointer(&json)), path) - // safely get the string headers - rawhi := *(*reflect.StringHeader)(unsafe.Pointer(&result.Raw)) - strhi := *(*reflect.StringHeader)(unsafe.Pointer(&result.Str)) - // create byte slice headers - rawh := reflect.SliceHeader{Data: rawhi.Data, Len: rawhi.Len} - strh := reflect.SliceHeader{Data: strhi.Data, Len: strhi.Len} - if strh.Data == 0 { - // str is nil - if rawh.Data == 0 { - // raw is nil - result.Raw = "" - } else { - // raw has data, safely copy the slice header to a string - result.Raw = string(*(*[]byte)(unsafe.Pointer(&rawh))) - } - result.Str = "" - } else if rawh.Data == 0 { - // raw is nil - result.Raw = "" - // str has data, safely copy the slice header to a string - result.Str = string(*(*[]byte)(unsafe.Pointer(&strh))) - } else if strh.Data >= rawh.Data && - int(strh.Data)+strh.Len <= int(rawh.Data)+rawh.Len { - // Str is a substring of Raw. - start := int(strh.Data - rawh.Data) - // safely copy the raw slice header - result.Raw = string(*(*[]byte)(unsafe.Pointer(&rawh))) - // substring the raw - result.Str = result.Raw[start : start+strh.Len] - } else { - // safely copy both the raw and str slice headers to strings - result.Raw = string(*(*[]byte)(unsafe.Pointer(&rawh))) - result.Str = string(*(*[]byte)(unsafe.Pointer(&strh))) - } - } - return result -} - -// fillIndex finds the position of Raw data and assigns it to the Index field -// of the resulting value. If the position cannot be found then Index zero is -// used instead. -func fillIndex(json string, c *parseContext) { - if len(c.value.Raw) > 0 && !c.calcd { - jhdr := *(*reflect.StringHeader)(unsafe.Pointer(&json)) - rhdr := *(*reflect.StringHeader)(unsafe.Pointer(&(c.value.Raw))) - c.value.Index = int(rhdr.Data - jhdr.Data) - if c.value.Index < 0 || c.value.Index >= len(json) { - c.value.Index = 0 - } - } -} - -func stringBytes(s string) []byte { - return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ - Data: (*reflect.StringHeader)(unsafe.Pointer(&s)).Data, - Len: len(s), - Cap: len(s), - })) -} - -func bytesString(b []byte) string { - return *(*string)(unsafe.Pointer(&b)) -} diff --git a/vendor/github.com/tidwall/gjson/go.mod b/vendor/github.com/tidwall/gjson/go.mod deleted file mode 100644 index d851688..0000000 --- a/vendor/github.com/tidwall/gjson/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module github.com/tidwall/gjson - -go 1.12 - -require ( - github.com/tidwall/match v1.0.1 - github.com/tidwall/pretty v1.0.0 -) diff --git a/vendor/github.com/tidwall/gjson/go.sum b/vendor/github.com/tidwall/gjson/go.sum deleted file mode 100644 index a4a2d87..0000000 --- a/vendor/github.com/tidwall/gjson/go.sum +++ /dev/null @@ -1,4 +0,0 @@ -github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= -github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= -github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= diff --git a/vendor/github.com/tidwall/gjson/logo.png b/vendor/github.com/tidwall/gjson/logo.png deleted file mode 100644 index 17a8bbe..0000000 Binary files a/vendor/github.com/tidwall/gjson/logo.png and /dev/null differ diff --git a/vendor/github.com/tidwall/match/LICENSE b/vendor/github.com/tidwall/match/LICENSE deleted file mode 100644 index 58f5819..0000000 --- a/vendor/github.com/tidwall/match/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2016 Josh Baker - -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/vendor/github.com/tidwall/match/README.md b/vendor/github.com/tidwall/match/README.md deleted file mode 100644 index 2aa5bc3..0000000 --- a/vendor/github.com/tidwall/match/README.md +++ /dev/null @@ -1,32 +0,0 @@ -Match -===== -Build Status -GoDoc - -Match is a very simple pattern matcher where '*' matches on any -number characters and '?' matches on any one character. - -Installing ----------- - -``` -go get -u github.com/tidwall/match -``` - -Example -------- - -```go -match.Match("hello", "*llo") -match.Match("jello", "?ello") -match.Match("hello", "h*o") -``` - - -Contact -------- -Josh Baker [@tidwall](http://twitter.com/tidwall) - -License -------- -Redcon source code is available under the MIT [License](/LICENSE). diff --git a/vendor/github.com/tidwall/match/match.go b/vendor/github.com/tidwall/match/match.go deleted file mode 100644 index fcfe998..0000000 --- a/vendor/github.com/tidwall/match/match.go +++ /dev/null @@ -1,181 +0,0 @@ -// Match provides a simple pattern matcher with unicode support. -package match - -import "unicode/utf8" - -// Match returns true if str matches pattern. This is a very -// simple wildcard match where '*' matches on any number characters -// and '?' matches on any one character. - -// pattern: -// { term } -// term: -// '*' matches any sequence of non-Separator characters -// '?' matches any single non-Separator character -// c matches character c (c != '*', '?', '\\') -// '\\' c matches character c -// -func Match(str, pattern string) bool { - if pattern == "*" { - return true - } - return deepMatch(str, pattern) -} -func deepMatch(str, pattern string) bool { - for len(pattern) > 0 { - if pattern[0] > 0x7f { - return deepMatchRune(str, pattern) - } - switch pattern[0] { - default: - if len(str) == 0 { - return false - } - if str[0] > 0x7f { - return deepMatchRune(str, pattern) - } - if str[0] != pattern[0] { - return false - } - case '?': - if len(str) == 0 { - return false - } - case '*': - return deepMatch(str, pattern[1:]) || - (len(str) > 0 && deepMatch(str[1:], pattern)) - } - str = str[1:] - pattern = pattern[1:] - } - return len(str) == 0 && len(pattern) == 0 -} - -func deepMatchRune(str, pattern string) bool { - var sr, pr rune - var srsz, prsz int - - // read the first rune ahead of time - if len(str) > 0 { - if str[0] > 0x7f { - sr, srsz = utf8.DecodeRuneInString(str) - } else { - sr, srsz = rune(str[0]), 1 - } - } else { - sr, srsz = utf8.RuneError, 0 - } - if len(pattern) > 0 { - if pattern[0] > 0x7f { - pr, prsz = utf8.DecodeRuneInString(pattern) - } else { - pr, prsz = rune(pattern[0]), 1 - } - } else { - pr, prsz = utf8.RuneError, 0 - } - // done reading - for pr != utf8.RuneError { - switch pr { - default: - if srsz == utf8.RuneError { - return false - } - if sr != pr { - return false - } - case '?': - if srsz == utf8.RuneError { - return false - } - case '*': - return deepMatchRune(str, pattern[prsz:]) || - (srsz > 0 && deepMatchRune(str[srsz:], pattern)) - } - str = str[srsz:] - pattern = pattern[prsz:] - // read the next runes - if len(str) > 0 { - if str[0] > 0x7f { - sr, srsz = utf8.DecodeRuneInString(str) - } else { - sr, srsz = rune(str[0]), 1 - } - } else { - sr, srsz = utf8.RuneError, 0 - } - if len(pattern) > 0 { - if pattern[0] > 0x7f { - pr, prsz = utf8.DecodeRuneInString(pattern) - } else { - pr, prsz = rune(pattern[0]), 1 - } - } else { - pr, prsz = utf8.RuneError, 0 - } - // done reading - } - - return srsz == 0 && prsz == 0 -} - -var maxRuneBytes = func() []byte { - b := make([]byte, 4) - if utf8.EncodeRune(b, '\U0010FFFF') != 4 { - panic("invalid rune encoding") - } - return b -}() - -// Allowable parses the pattern and determines the minimum and maximum allowable -// values that the pattern can represent. -// When the max cannot be determined, 'true' will be returned -// for infinite. -func Allowable(pattern string) (min, max string) { - if pattern == "" || pattern[0] == '*' { - return "", "" - } - - minb := make([]byte, 0, len(pattern)) - maxb := make([]byte, 0, len(pattern)) - var wild bool - for i := 0; i < len(pattern); i++ { - if pattern[i] == '*' { - wild = true - break - } - if pattern[i] == '?' { - minb = append(minb, 0) - maxb = append(maxb, maxRuneBytes...) - } else { - minb = append(minb, pattern[i]) - maxb = append(maxb, pattern[i]) - } - } - if wild { - r, n := utf8.DecodeLastRune(maxb) - if r != utf8.RuneError { - if r < utf8.MaxRune { - r++ - if r > 0x7f { - b := make([]byte, 4) - nn := utf8.EncodeRune(b, r) - maxb = append(maxb[:len(maxb)-n], b[:nn]...) - } else { - maxb = append(maxb[:len(maxb)-n], byte(r)) - } - } - } - } - return string(minb), string(maxb) -} - -// IsPattern returns true if the string is a pattern. -func IsPattern(str string) bool { - for i := 0; i < len(str); i++ { - if str[i] == '*' || str[i] == '?' { - return true - } - } - return false -} diff --git a/vendor/github.com/tidwall/pretty/LICENSE b/vendor/github.com/tidwall/pretty/LICENSE deleted file mode 100644 index 993b83f..0000000 --- a/vendor/github.com/tidwall/pretty/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2017 Josh Baker - -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/vendor/github.com/tidwall/pretty/README.md b/vendor/github.com/tidwall/pretty/README.md deleted file mode 100644 index d2b8864..0000000 --- a/vendor/github.com/tidwall/pretty/README.md +++ /dev/null @@ -1,124 +0,0 @@ -# Pretty -[![Build Status](https://img.shields.io/travis/tidwall/pretty.svg?style=flat-square)](https://travis-ci.org/tidwall/prettty) -[![Coverage Status](https://img.shields.io/badge/coverage-100%25-brightgreen.svg?style=flat-square)](http://gocover.io/github.com/tidwall/pretty) -[![GoDoc](https://img.shields.io/badge/api-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/tidwall/pretty) - - -Pretty is a Go package that provides [fast](#performance) methods for formatting JSON for human readability, or to compact JSON for smaller payloads. - -Getting Started -=============== - -## Installing - -To start using Pretty, install Go and run `go get`: - -```sh -$ go get -u github.com/tidwall/pretty -``` - -This will retrieve the library. - -## Pretty - -Using this example: - -```json -{"name": {"first":"Tom","last":"Anderson"}, "age":37, -"children": ["Sara","Alex","Jack"], -"fav.movie": "Deer Hunter", "friends": [ - {"first": "Janet", "last": "Murphy", "age": 44} - ]} -``` - -The following code: -```go -result = pretty.Pretty(example) -``` - -Will format the json to: - -```json -{ - "name": { - "first": "Tom", - "last": "Anderson" - }, - "age": 37, - "children": ["Sara", "Alex", "Jack"], - "fav.movie": "Deer Hunter", - "friends": [ - { - "first": "Janet", - "last": "Murphy", - "age": 44 - } - ] -} -``` - -## Color - -Color will colorize the json for outputing to the screen. - -```json -result = pretty.Color(json, nil) -``` - -Will add color to the result for printing to the terminal. -The second param is used for a customizing the style, and passing nil will use the default `pretty.TerminalStyle`. - -## Ugly - -The following code: -```go -result = pretty.Ugly(example) -``` - -Will format the json to: - -```json -{"name":{"first":"Tom","last":"Anderson"},"age":37,"children":["Sara","Alex","Jack"],"fav.movie":"Deer Hunter","friends":[{"first":"Janet","last":"Murphy","age":44}]}``` -``` - - -## Customized output - -There's a `PrettyOptions(json, opts)` function which allows for customizing the output with the following options: - -```go -type Options struct { - // Width is an max column width for single line arrays - // Default is 80 - Width int - // Prefix is a prefix for all lines - // Default is an empty string - Prefix string - // Indent is the nested indentation - // Default is two spaces - Indent string - // SortKeys will sort the keys alphabetically - // Default is false - SortKeys bool -} -``` -## Performance - -Benchmarks of Pretty alongside the builtin `encoding/json` Indent/Compact methods. -``` -BenchmarkPretty-8 1000000 1283 ns/op 720 B/op 2 allocs/op -BenchmarkUgly-8 3000000 426 ns/op 240 B/op 1 allocs/op -BenchmarkUglyInPlace-8 5000000 340 ns/op 0 B/op 0 allocs/op -BenchmarkJSONIndent-8 300000 4628 ns/op 1069 B/op 4 allocs/op -BenchmarkJSONCompact-8 1000000 2469 ns/op 758 B/op 4 allocs/op -``` - -*These benchmarks were run on a MacBook Pro 15" 2.8 GHz Intel Core i7 using Go 1.7.* - -## Contact -Josh Baker [@tidwall](http://twitter.com/tidwall) - -## License - -Pretty source code is available under the MIT [License](/LICENSE). - diff --git a/vendor/github.com/tidwall/pretty/pretty.go b/vendor/github.com/tidwall/pretty/pretty.go deleted file mode 100644 index 0a922d0..0000000 --- a/vendor/github.com/tidwall/pretty/pretty.go +++ /dev/null @@ -1,432 +0,0 @@ -package pretty - -import ( - "sort" -) - -// Options is Pretty options -type Options struct { - // Width is an max column width for single line arrays - // Default is 80 - Width int - // Prefix is a prefix for all lines - // Default is an empty string - Prefix string - // Indent is the nested indentation - // Default is two spaces - Indent string - // SortKeys will sort the keys alphabetically - // Default is false - SortKeys bool -} - -// DefaultOptions is the default options for pretty formats. -var DefaultOptions = &Options{Width: 80, Prefix: "", Indent: " ", SortKeys: false} - -// Pretty converts the input json into a more human readable format where each -// element is on it's own line with clear indentation. -func Pretty(json []byte) []byte { return PrettyOptions(json, nil) } - -// PrettyOptions is like Pretty but with customized options. -func PrettyOptions(json []byte, opts *Options) []byte { - if opts == nil { - opts = DefaultOptions - } - buf := make([]byte, 0, len(json)) - if len(opts.Prefix) != 0 { - buf = append(buf, opts.Prefix...) - } - buf, _, _, _ = appendPrettyAny(buf, json, 0, true, - opts.Width, opts.Prefix, opts.Indent, opts.SortKeys, - 0, 0, -1) - if len(buf) > 0 { - buf = append(buf, '\n') - } - return buf -} - -// Ugly removes insignificant space characters from the input json byte slice -// and returns the compacted result. -func Ugly(json []byte) []byte { - buf := make([]byte, 0, len(json)) - return ugly(buf, json) -} - -// UglyInPlace removes insignificant space characters from the input json -// byte slice and returns the compacted result. This method reuses the -// input json buffer to avoid allocations. Do not use the original bytes -// slice upon return. -func UglyInPlace(json []byte) []byte { return ugly(json, json) } - -func ugly(dst, src []byte) []byte { - dst = dst[:0] - for i := 0; i < len(src); i++ { - if src[i] > ' ' { - dst = append(dst, src[i]) - if src[i] == '"' { - for i = i + 1; i < len(src); i++ { - dst = append(dst, src[i]) - if src[i] == '"' { - j := i - 1 - for ; ; j-- { - if src[j] != '\\' { - break - } - } - if (j-i)%2 != 0 { - break - } - } - } - } - } - } - return dst -} - -func appendPrettyAny(buf, json []byte, i int, pretty bool, width int, prefix, indent string, sortkeys bool, tabs, nl, max int) ([]byte, int, int, bool) { - for ; i < len(json); i++ { - if json[i] <= ' ' { - continue - } - if json[i] == '"' { - return appendPrettyString(buf, json, i, nl) - } - if (json[i] >= '0' && json[i] <= '9') || json[i] == '-' { - return appendPrettyNumber(buf, json, i, nl) - } - if json[i] == '{' { - return appendPrettyObject(buf, json, i, '{', '}', pretty, width, prefix, indent, sortkeys, tabs, nl, max) - } - if json[i] == '[' { - return appendPrettyObject(buf, json, i, '[', ']', pretty, width, prefix, indent, sortkeys, tabs, nl, max) - } - switch json[i] { - case 't': - return append(buf, 't', 'r', 'u', 'e'), i + 4, nl, true - case 'f': - return append(buf, 'f', 'a', 'l', 's', 'e'), i + 5, nl, true - case 'n': - return append(buf, 'n', 'u', 'l', 'l'), i + 4, nl, true - } - } - return buf, i, nl, true -} - -type pair struct { - kstart, kend int - vstart, vend int -} - -type byKey struct { - sorted bool - json []byte - pairs []pair -} - -func (arr *byKey) Len() int { - return len(arr.pairs) -} -func (arr *byKey) Less(i, j int) bool { - key1 := arr.json[arr.pairs[i].kstart+1 : arr.pairs[i].kend-1] - key2 := arr.json[arr.pairs[j].kstart+1 : arr.pairs[j].kend-1] - return string(key1) < string(key2) -} -func (arr *byKey) Swap(i, j int) { - arr.pairs[i], arr.pairs[j] = arr.pairs[j], arr.pairs[i] - arr.sorted = true -} - -func appendPrettyObject(buf, json []byte, i int, open, close byte, pretty bool, width int, prefix, indent string, sortkeys bool, tabs, nl, max int) ([]byte, int, int, bool) { - var ok bool - if width > 0 { - if pretty && open == '[' && max == -1 { - // here we try to create a single line array - max := width - (len(buf) - nl) - if max > 3 { - s1, s2 := len(buf), i - buf, i, _, ok = appendPrettyObject(buf, json, i, '[', ']', false, width, prefix, "", sortkeys, 0, 0, max) - if ok && len(buf)-s1 <= max { - return buf, i, nl, true - } - buf = buf[:s1] - i = s2 - } - } else if max != -1 && open == '{' { - return buf, i, nl, false - } - } - buf = append(buf, open) - i++ - var pairs []pair - if open == '{' && sortkeys { - pairs = make([]pair, 0, 8) - } - var n int - for ; i < len(json); i++ { - if json[i] <= ' ' { - continue - } - if json[i] == close { - if pretty { - if open == '{' && sortkeys { - buf = sortPairs(json, buf, pairs) - } - if n > 0 { - nl = len(buf) - buf = append(buf, '\n') - } - if buf[len(buf)-1] != open { - buf = appendTabs(buf, prefix, indent, tabs) - } - } - buf = append(buf, close) - return buf, i + 1, nl, open != '{' - } - if open == '[' || json[i] == '"' { - if n > 0 { - buf = append(buf, ',') - if width != -1 && open == '[' { - buf = append(buf, ' ') - } - } - var p pair - if pretty { - nl = len(buf) - buf = append(buf, '\n') - if open == '{' && sortkeys { - p.kstart = i - p.vstart = len(buf) - } - buf = appendTabs(buf, prefix, indent, tabs+1) - } - if open == '{' { - buf, i, nl, _ = appendPrettyString(buf, json, i, nl) - if sortkeys { - p.kend = i - } - buf = append(buf, ':') - if pretty { - buf = append(buf, ' ') - } - } - buf, i, nl, ok = appendPrettyAny(buf, json, i, pretty, width, prefix, indent, sortkeys, tabs+1, nl, max) - if max != -1 && !ok { - return buf, i, nl, false - } - if pretty && open == '{' && sortkeys { - p.vend = len(buf) - if p.kstart > p.kend || p.vstart > p.vend { - // bad data. disable sorting - sortkeys = false - } else { - pairs = append(pairs, p) - } - } - i-- - n++ - } - } - return buf, i, nl, open != '{' -} -func sortPairs(json, buf []byte, pairs []pair) []byte { - if len(pairs) == 0 { - return buf - } - vstart := pairs[0].vstart - vend := pairs[len(pairs)-1].vend - arr := byKey{false, json, pairs} - sort.Sort(&arr) - if !arr.sorted { - return buf - } - nbuf := make([]byte, 0, vend-vstart) - for i, p := range pairs { - nbuf = append(nbuf, buf[p.vstart:p.vend]...) - if i < len(pairs)-1 { - nbuf = append(nbuf, ',') - nbuf = append(nbuf, '\n') - } - } - return append(buf[:vstart], nbuf...) -} - -func appendPrettyString(buf, json []byte, i, nl int) ([]byte, int, int, bool) { - s := i - i++ - for ; i < len(json); i++ { - if json[i] == '"' { - var sc int - for j := i - 1; j > s; j-- { - if json[j] == '\\' { - sc++ - } else { - break - } - } - if sc%2 == 1 { - continue - } - i++ - break - } - } - return append(buf, json[s:i]...), i, nl, true -} - -func appendPrettyNumber(buf, json []byte, i, nl int) ([]byte, int, int, bool) { - s := i - i++ - for ; i < len(json); i++ { - if json[i] <= ' ' || json[i] == ',' || json[i] == ':' || json[i] == ']' || json[i] == '}' { - break - } - } - return append(buf, json[s:i]...), i, nl, true -} - -func appendTabs(buf []byte, prefix, indent string, tabs int) []byte { - if len(prefix) != 0 { - buf = append(buf, prefix...) - } - if len(indent) == 2 && indent[0] == ' ' && indent[1] == ' ' { - for i := 0; i < tabs; i++ { - buf = append(buf, ' ', ' ') - } - } else { - for i := 0; i < tabs; i++ { - buf = append(buf, indent...) - } - } - return buf -} - -// Style is the color style -type Style struct { - Key, String, Number [2]string - True, False, Null [2]string - Append func(dst []byte, c byte) []byte -} - -func hexp(p byte) byte { - switch { - case p < 10: - return p + '0' - default: - return (p - 10) + 'a' - } -} - -// TerminalStyle is for terminals -var TerminalStyle = &Style{ - Key: [2]string{"\x1B[94m", "\x1B[0m"}, - String: [2]string{"\x1B[92m", "\x1B[0m"}, - Number: [2]string{"\x1B[93m", "\x1B[0m"}, - True: [2]string{"\x1B[96m", "\x1B[0m"}, - False: [2]string{"\x1B[96m", "\x1B[0m"}, - Null: [2]string{"\x1B[91m", "\x1B[0m"}, - Append: func(dst []byte, c byte) []byte { - if c < ' ' && (c != '\r' && c != '\n' && c != '\t' && c != '\v') { - dst = append(dst, "\\u00"...) - dst = append(dst, hexp((c>>4)&0xF)) - return append(dst, hexp((c)&0xF)) - } - return append(dst, c) - }, -} - -// Color will colorize the json. The style parma is used for customizing -// the colors. Passing nil to the style param will use the default -// TerminalStyle. -func Color(src []byte, style *Style) []byte { - if style == nil { - style = TerminalStyle - } - apnd := style.Append - if apnd == nil { - apnd = func(dst []byte, c byte) []byte { - return append(dst, c) - } - } - type stackt struct { - kind byte - key bool - } - var dst []byte - var stack []stackt - for i := 0; i < len(src); i++ { - if src[i] == '"' { - key := len(stack) > 0 && stack[len(stack)-1].key - if key { - dst = append(dst, style.Key[0]...) - } else { - dst = append(dst, style.String[0]...) - } - dst = apnd(dst, '"') - for i = i + 1; i < len(src); i++ { - dst = apnd(dst, src[i]) - if src[i] == '"' { - j := i - 1 - for ; ; j-- { - if src[j] != '\\' { - break - } - } - if (j-i)%2 != 0 { - break - } - } - } - if key { - dst = append(dst, style.Key[1]...) - } else { - dst = append(dst, style.String[1]...) - } - } else if src[i] == '{' || src[i] == '[' { - stack = append(stack, stackt{src[i], src[i] == '{'}) - dst = apnd(dst, src[i]) - } else if (src[i] == '}' || src[i] == ']') && len(stack) > 0 { - stack = stack[:len(stack)-1] - dst = apnd(dst, src[i]) - } else if (src[i] == ':' || src[i] == ',') && len(stack) > 0 && stack[len(stack)-1].kind == '{' { - stack[len(stack)-1].key = !stack[len(stack)-1].key - dst = apnd(dst, src[i]) - } else { - var kind byte - if (src[i] >= '0' && src[i] <= '9') || src[i] == '-' { - kind = '0' - dst = append(dst, style.Number[0]...) - } else if src[i] == 't' { - kind = 't' - dst = append(dst, style.True[0]...) - } else if src[i] == 'f' { - kind = 'f' - dst = append(dst, style.False[0]...) - } else if src[i] == 'n' { - kind = 'n' - dst = append(dst, style.Null[0]...) - } else { - dst = apnd(dst, src[i]) - } - if kind != 0 { - for ; i < len(src); i++ { - if src[i] <= ' ' || src[i] == ',' || src[i] == ':' || src[i] == ']' || src[i] == '}' { - i-- - break - } - dst = apnd(dst, src[i]) - } - if kind == '0' { - dst = append(dst, style.Number[1]...) - } else if kind == 't' { - dst = append(dst, style.True[1]...) - } else if kind == 'f' { - dst = append(dst, style.False[1]...) - } else if kind == 'n' { - dst = append(dst, style.Null[1]...) - } - } - } - } - return dst -} diff --git a/vendor/github.com/twpayne/go-geom/INTERNALS.md b/vendor/github.com/twpayne/go-geom/INTERNALS.md deleted file mode 100644 index 8e15301..0000000 --- a/vendor/github.com/twpayne/go-geom/INTERNALS.md +++ /dev/null @@ -1,119 +0,0 @@ -# `go-geom` Internals - - -## Introduction - -`go-geom` attempts to implement efficient, standards-compatible OGC-style -geometries for Go. This document describes some of the key ideas required to -understand its implementation. - -`go-geom` is an evolution of the techniques developed for the [OpenLayers 3 -geometry library](http://openlayers.org/en/master/apidoc/ol.geom.html), -designed to efficiently handle large geometries in a resource-constrained, -garbage-collected environment, but adapted to the Go programming language and -its type system. - - -## Type flexibility - -There are three priniciple 2D geometry types: `Point`s, `LineString`s, and -`Polygon`s. - -OGC extends these three into collections of the principle types: `MultiPoint`, -`MultiLineString`, and `MultiPolygon`. This gives 3 geometry types * 2 -multi-or-not-multi = 6 combinations. - -On top of this, there are multiple combinations of dimensions, e.g. 2D (XY), 3D -(XYZ), 2D varying over time/distance (XYM), and 3D varying over time/distance -(XYZM). - -3 geometry types * 2 multi-or-not-multi * 4 different dimensionalities = 24 -distinct types. - -Go has neither generics, nor macros, nor a rich type system. `go-geom` attempts -to manage this combinatorial explosion while maintaining an idiomatic Go API, -implementation efficiency. and high runtime performance. - - -## Structural similarity - -`go-geom` exploits structural similarity between different geometry types to -share code. Consider: - -0. A `Point` consists of a single coordinate. This single coordinate is a - `geom.Coord`. - -1. A `LineString`, `LinearRing`, and `MultiPoint` consist of a collection of - coordinates. They all have different semantics (a `LineString` is ordered, -a `LinearRing` is ordered and closed, a `MultiPoint` is neither ordered nor -closed) yet all share a similar underlying structure. - -2. A `Polygon` and a `MultiLineString` are a collection of collections of - coordinates. Again, the semantics vary: a `Polygon` is a weakly ordered -collection of `LinearRing`s (the first `LinearRing` is the outer boundary, -subsequent `LinearRing`s are inner boundaries (holes)). A `MultiLineString` is -an unordered collection of `LineString`s. - -3. A `MultiPolygon` is an unordered collection of `Polygon`s. - -`go-geom` makes these structural similarities explicit: - -0. A `Point` is a `geom.Coord`, also known as `geom0`. - -1. `LineString`s, `LinearRing`s, and and `MultiPoint`s are `[]geom.Coord`, also - known as `geom1`. - -2. `Polygon`s and `MultiLineString`s are `[][]geom.Coord`, also known as - `geom2`. - -3. `MultiPolygon`s are `[][][]geom.Coord`, also known as `geom3`. - -Under the hood, `go-geom` uses Go's structural composition to share common -code. For example, `LineString`s, `LinearRing`s, and `MultiPoint`s all embed a -single anonymous `geom1`. - -The hierarchy of embedding is: - - geom0 - +- geom1 - +- geom2 - +- geom3 - -Note that `geom2` and `geom3` independently embed `geom1`. Despite their -numerical ordering, `geom2` and `geom3` are separate branches of the geometry -tree. - -We can exploit these structural similarities to share code. For example, -calculating the bounds of a geometry only involves finding the minimum and -maximum values in each dimension, which can be found by iterating over all -coordinates in the geometry. The semantic meaning of these coordinates - -whether they're points on a line, or points on a polygon inner or outer -boundary, or something else - does not matter. Therefore, as long as we can -treat any geometry as a collection of coordinates, we can use the same code to -calculate bounds across all geometry types. - -Similarly, we can exploit higher-level similarities. For example, the "length" -of a `MultiLineString` is the sum of the lengths of its component -`LineString`s, and the "length" (perimeter) of a `Polygon` is the sum of the -lengths (perimeters) of its component `LinearRing`s. - - -## Efficient - -At the time of writing (2016), CPUs are fast, cache hits are quite fast, cache -misses are slow, memory is very slow, and garbage collection takes an eternity. - -Typical geometry libraries use multiple levels of nested arrays, e.g. a -`[][][]float64` for a polygon. This requires multiple levels of indirection to -access a single coordinate value, and as different sub-arrays might be stored -in different parts of memory, is more likely to lead to cache miss. - -In contrast, `go-geom` packs all the coordinates for a geometry, whatever its -structure, into a single `[]float64`. The underlying array is stored in a -single blob of memory. Most operations do a linear scan over the array, which -is particularly cache friendly. There are also fewer objects for the garbage -collector to manage. - -Parts of the underlying array can be shared between multitple objects. For -example, retrieving the outer ring of a `Polygon` returns a `LinearRing` that -references the coordinates of the `Polygon`. No coordinate data are copied. diff --git a/vendor/github.com/twpayne/go-geom/LICENSE b/vendor/github.com/twpayne/go-geom/LICENSE deleted file mode 100644 index 3bc8155..0000000 --- a/vendor/github.com/twpayne/go-geom/LICENSE +++ /dev/null @@ -1,23 +0,0 @@ -Copyright (c) 2013, Tom Payne -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - - Redistributions in binary form must reproduce the above copyright notice, this - list of conditions and the following disclaimer in the documentation and/or - other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/vendor/github.com/twpayne/go-geom/README.md b/vendor/github.com/twpayne/go-geom/README.md deleted file mode 100644 index 2472aba..0000000 --- a/vendor/github.com/twpayne/go-geom/README.md +++ /dev/null @@ -1,77 +0,0 @@ -# go-geom - -[![Build Status](https://travis-ci.org/twpayne/go-geom.svg?branch=master)](https://travis-ci.org/twpayne/go-geom) -[![GoDoc](https://godoc.org/github.com/twpayne/go-geom?status.svg)](https://godoc.org/github.com/twpayne/go-geom) -[![Go Report Card](https://goreportcard.com/badge/github.com/twpayne/go-geom)](https://goreportcard.com/report/github.com/twpayne/go-geom) -[![Coverage Status](https://coveralls.io/repos/github/twpayne/go-geom/badge.svg)](https://coveralls.io/github/twpayne/go-geom) - -Package `geom` implements efficient geometry types for geospatial applications. - -## Key features - -* OpenGeo Consortium-style geometries. -* Support for 2D and 3D geometries, measures (time and/or distance), and - unlimited extra dimensions. -* Encoding and decoding of common geometry formats (GeoJSON, KML, WKB, and - others) including [`sql.Scanner`](https://godoc.org/database/sql#Scanner) and - [`driver.Value`](https://godoc.org/database/sql/driver#Value) interface - implementations for easy database integration. -* [2D](https://godoc.org/github.com/twpayne/go-geom/xy) and - [3D](https://godoc.org/github.com/twpayne/go-geom/xyz) topology functions. -* Efficient, cache-friendly [internal representation](INTERNALS.md). -* Optional protection against malicious or malformed inputs. - -## Examples - -* [PostGIS, EWKB, and GeoJSON](https://github.com/twpayne/go-geom/tree/master/examples/postgis). - -## Detailed features - -### Geometry types - -* [Point](https://godoc.org/github.com/twpayne/go-geom#Point) -* [LineString](https://godoc.org/github.com/twpayne/go-geom#LineString) -* [Polygon](https://godoc.org/github.com/twpayne/go-geom#Polygon) -* [MultiPoint](https://godoc.org/github.com/twpayne/go-geom#MultiPoint) -* [MultiLineString](https://godoc.org/github.com/twpayne/go-geom#MultiLineString) -* [MultiPolygon](https://godoc.org/github.com/twpayne/go-geom#MultiPolygon) -* [GeometryCollection](https://godoc.org/github.com/twpayne/go-geom#GeometryCollection) - -### Encoding and decoding - -* [GeoJSON](https://godoc.org/github.com/twpayne/go-geom/encoding/geojson) -* [IGC](https://godoc.org/github.com/twpayne/go-geom/encoding/igc) -* [KML](https://godoc.org/github.com/twpayne/go-geom/encoding/kml) (encoding only) -* [WKB](https://godoc.org/github.com/twpayne/go-geom/encoding/wkb) -* [EWKB](https://godoc.org/github.com/twpayne/go-geom/encoding/ewkb) -* [WKT](https://godoc.org/github.com/twpayne/go-geom/encoding/wkt) (encoding only) -* [WKB Hex](https://godoc.org/github.com/twpayne/go-geom/encoding/wkbhex) -* [EWKB Hex](https://godoc.org/github.com/twpayne/go-geom/encoding/ewkbhex) - -### Geometry functions - -* [XY](https://godoc.org/github.com/twpayne/go-geom/xy) 2D geometry functions -* [XYZ](https://godoc.org/github.com/twpayne/go-geom/xyz) 3D geometry functions - -## Protection against malicious or malformed inputs - -The WKB and EWKB formats encode geometry sizes, and memory is allocated for -those geometries. If the input is malicious or malformed, the memory allocation -can be very large, leading to a memory starvation denial-of-service attack -against the server. For example, a client might send a `MultiPoint` with header -indicating that it contains 2^32-1 points. This will result in the server -reading that geometry to allocate 2 × `sizeof(float64)` × (2^32-1) = 64GB of -memory to store those points. By default, malicious or malformed input -protection is disabled, but can be enabled by setting positive values for -`wkbcommon.MaxGeometryElements`. - -## Related libraries - -* [github.com/twpayne/go-gpx](https://github.com/twpayne/go-gpx) GPX encoding and decoding -* [github.com/twpayne/go-kml](https://github.com/twpayne/go-kml) KML encoding -* [github.com/twpayne/go-polyline](https://github.com/twpayne/go-polyline) Google Maps Polyline encoding and decoding -* [github.com/twpayne/go-vali](https://github.com/twpayne/go-vali) IGC validation - -## License - -BSD-2-Clause \ No newline at end of file diff --git a/vendor/github.com/twpayne/go-geom/bounds.go b/vendor/github.com/twpayne/go-geom/bounds.go deleted file mode 100644 index ab43980..0000000 --- a/vendor/github.com/twpayne/go-geom/bounds.go +++ /dev/null @@ -1,178 +0,0 @@ -package geom - -import "math" - -// A Bounds represents a multi-dimensional bounding box. -type Bounds struct { - layout Layout - min Coord - max Coord -} - -// NewBounds creates a new Bounds. -func NewBounds(layout Layout) *Bounds { - stride := layout.Stride() - min, max := make(Coord, stride), make(Coord, stride) - for i := 0; i < stride; i++ { - min[i], max[i] = math.Inf(1), math.Inf(-1) - } - return &Bounds{ - layout: layout, - min: min, - max: max, - } -} - -// Clone returns a deep copy of b. -func (b *Bounds) Clone() *Bounds { - return deriveCloneBounds(b) -} - -// Extend extends b to include geometry g. -func (b *Bounds) Extend(g T) *Bounds { - b.extendLayout(g.Layout()) - if b.layout == XYZM && g.Layout() == XYM { - return b.extendXYZMFlatCoordsWithXYM(g.FlatCoords(), 0, len(g.FlatCoords())) - } - return b.extendFlatCoords(g.FlatCoords(), 0, len(g.FlatCoords()), g.Stride()) -} - -// IsEmpty returns true if b is empty. -func (b *Bounds) IsEmpty() bool { - if b.layout == NoLayout { - return true - } - for i, stride := 0, b.layout.Stride(); i < stride; i++ { - if b.max[i] < b.min[i] { - return true - } - } - return false -} - -// Layout returns b's layout. -func (b *Bounds) Layout() Layout { - return b.layout -} - -// Max returns the maximum value in dimension dim. -func (b *Bounds) Max(dim int) float64 { - return b.max[dim] -} - -// Min returns the minimum value in dimension dim. -func (b *Bounds) Min(dim int) float64 { - return b.min[dim] -} - -// Overlaps returns true if b overlaps b2 in layout. -func (b *Bounds) Overlaps(layout Layout, b2 *Bounds) bool { - for i, stride := 0, layout.Stride(); i < stride; i++ { - if b.min[i] > b2.max[i] || b.max[i] < b2.min[i] { - return false - } - } - return true -} - -// Polygon returns b as a two-dimensional Polygon. -func (b *Bounds) Polygon() *Polygon { - if b.IsEmpty() { - return NewPolygonFlat(XY, nil, nil) - } - x1, y1 := b.min[0], b.min[1] - x2, y2 := b.max[0], b.max[1] - flatCoords := []float64{ - x1, y1, - x1, y2, - x2, y2, - x2, y1, - x1, y1, - } - return NewPolygonFlat(XY, flatCoords, []int{len(flatCoords)}) -} - -// Set sets the minimum and maximum values. args must be an even number of -// values: the first half are the minimum values for each dimension and the -// second half are the maximum values for each dimension. If necessary, the -// layout of b will be extended to cover all the supplied dimensions implied by -// args. -func (b *Bounds) Set(args ...float64) *Bounds { - if len(args)&1 != 0 { - panic("geom: even number of arguments required") - } - stride := len(args) / 2 - b.extendStride(stride) - for i := 0; i < stride; i++ { - b.min[i], b.max[i] = args[i], args[i+stride] - } - return b -} - -// SetCoords sets the minimum and maximum values of the Bounds. -func (b *Bounds) SetCoords(min, max Coord) *Bounds { - b.min = Coord(make([]float64, b.layout.Stride())) - b.max = Coord(make([]float64, b.layout.Stride())) - for i := 0; i < b.layout.Stride(); i++ { - b.min[i] = math.Min(min[i], max[i]) - b.max[i] = math.Max(min[i], max[i]) - } - return b -} - -// OverlapsPoint determines if the bounding box overlaps the point (point is -// within or on the border of the bounds). -func (b *Bounds) OverlapsPoint(layout Layout, point Coord) bool { - for i, stride := 0, layout.Stride(); i < stride; i++ { - if b.min[i] > point[i] || b.max[i] < point[i] { - return false - } - } - return true -} - -func (b *Bounds) extendFlatCoords(flatCoords []float64, offset, end, stride int) *Bounds { - b.extendStride(stride) - for i := offset; i < end; i += stride { - for j := 0; j < stride; j++ { - b.min[j] = math.Min(b.min[j], flatCoords[i+j]) - b.max[j] = math.Max(b.max[j], flatCoords[i+j]) - } - } - return b -} - -func (b *Bounds) extendLayout(layout Layout) { - switch { - case b.layout == XYZ && layout == XYM: - b.min = append(b.min, math.Inf(1)) - b.max = append(b.max, math.Inf(-1)) - b.layout = XYZM - case b.layout == XYM && (layout == XYZ || layout == XYZM): - b.min = append(b.min[:2], math.Inf(1), b.min[2]) - b.max = append(b.max[:2], math.Inf(-1), b.max[2]) - b.layout = XYZM - case b.layout < layout: - b.extendStride(layout.Stride()) - b.layout = layout - } -} - -func (b *Bounds) extendStride(stride int) { - for s := b.layout.Stride(); s < stride; s++ { - b.min = append(b.min, math.Inf(1)) - b.max = append(b.max, math.Inf(-1)) - } -} - -func (b *Bounds) extendXYZMFlatCoordsWithXYM(flatCoords []float64, offset, end int) *Bounds { - for i := offset; i < end; i += 3 { - b.min[0] = math.Min(b.min[0], flatCoords[i+0]) - b.max[0] = math.Max(b.max[0], flatCoords[i+0]) - b.min[1] = math.Min(b.min[1], flatCoords[i+1]) - b.max[1] = math.Max(b.max[1], flatCoords[i+1]) - b.min[3] = math.Min(b.min[3], flatCoords[i+2]) - b.max[3] = math.Max(b.max[3], flatCoords[i+2]) - } - return b -} diff --git a/vendor/github.com/twpayne/go-geom/derived.gen.go b/vendor/github.com/twpayne/go-geom/derived.gen.go deleted file mode 100644 index a86c9b3..0000000 --- a/vendor/github.com/twpayne/go-geom/derived.gen.go +++ /dev/null @@ -1,314 +0,0 @@ -// Code generated by goderive DO NOT EDIT. - -package geom - -// deriveCloneBounds returns a clone of the src parameter. -func deriveCloneBounds(src *Bounds) *Bounds { - if src == nil { - return nil - } - dst := new(Bounds) - deriveDeepCopy(dst, src) - return dst -} - -// deriveCloneCoord returns a clone of the src parameter. -func deriveCloneCoord(src Coord) Coord { - if src == nil { - return nil - } - dst := make(Coord, len(src)) - deriveDeepCopy_(dst, src) - return dst -} - -// deriveCloneLinearRing returns a clone of the src parameter. -func deriveCloneLinearRing(src *LinearRing) *LinearRing { - if src == nil { - return nil - } - dst := new(LinearRing) - deriveDeepCopy_1(dst, src) - return dst -} - -// deriveCloneLineString returns a clone of the src parameter. -func deriveCloneLineString(src *LineString) *LineString { - if src == nil { - return nil - } - dst := new(LineString) - deriveDeepCopy_2(dst, src) - return dst -} - -// deriveCloneMultiLineString returns a clone of the src parameter. -func deriveCloneMultiLineString(src *MultiLineString) *MultiLineString { - if src == nil { - return nil - } - dst := new(MultiLineString) - deriveDeepCopy_3(dst, src) - return dst -} - -// deriveCloneMultiPoint returns a clone of the src parameter. -func deriveCloneMultiPoint(src *MultiPoint) *MultiPoint { - if src == nil { - return nil - } - dst := new(MultiPoint) - deriveDeepCopy_4(dst, src) - return dst -} - -// deriveCloneMultiPolygon returns a clone of the src parameter. -func deriveCloneMultiPolygon(src *MultiPolygon) *MultiPolygon { - if src == nil { - return nil - } - dst := new(MultiPolygon) - deriveDeepCopy_5(dst, src) - return dst -} - -// deriveClonePoint returns a clone of the src parameter. -func deriveClonePoint(src *Point) *Point { - if src == nil { - return nil - } - dst := new(Point) - deriveDeepCopy_6(dst, src) - return dst -} - -// deriveClonePolygon returns a clone of the src parameter. -func deriveClonePolygon(src *Polygon) *Polygon { - if src == nil { - return nil - } - dst := new(Polygon) - deriveDeepCopy_7(dst, src) - return dst -} - -// deriveDeepCopy recursively copies the contents of src into dst. -func deriveDeepCopy(dst, src *Bounds) { - dst.layout = src.layout - if src.min == nil { - dst.min = nil - } else { - if dst.min != nil { - if len(src.min) > len(dst.min) { - if cap(dst.min) >= len(src.min) { - dst.min = (dst.min)[:len(src.min)] - } else { - dst.min = make([]float64, len(src.min)) - } - } else if len(src.min) < len(dst.min) { - dst.min = (dst.min)[:len(src.min)] - } - } else { - dst.min = make([]float64, len(src.min)) - } - copy(dst.min, src.min) - } - if src.max == nil { - dst.max = nil - } else { - if dst.max != nil { - if len(src.max) > len(dst.max) { - if cap(dst.max) >= len(src.max) { - dst.max = (dst.max)[:len(src.max)] - } else { - dst.max = make([]float64, len(src.max)) - } - } else if len(src.max) < len(dst.max) { - dst.max = (dst.max)[:len(src.max)] - } - } else { - dst.max = make([]float64, len(src.max)) - } - copy(dst.max, src.max) - } -} - -// deriveDeepCopy_ recursively copies the contents of src into dst. -func deriveDeepCopy_(dst, src Coord) { - copy(dst, src) -} - -// deriveDeepCopy_1 recursively copies the contents of src into dst. -func deriveDeepCopy_1(dst, src *LinearRing) { - func() { - field := new(geom1) - deriveDeepCopy_8(field, &src.geom1) - dst.geom1 = *field - }() -} - -// deriveDeepCopy_2 recursively copies the contents of src into dst. -func deriveDeepCopy_2(dst, src *LineString) { - func() { - field := new(geom1) - deriveDeepCopy_8(field, &src.geom1) - dst.geom1 = *field - }() -} - -// deriveDeepCopy_3 recursively copies the contents of src into dst. -func deriveDeepCopy_3(dst, src *MultiLineString) { - func() { - field := new(geom2) - deriveDeepCopy_9(field, &src.geom2) - dst.geom2 = *field - }() -} - -// deriveDeepCopy_4 recursively copies the contents of src into dst. -func deriveDeepCopy_4(dst, src *MultiPoint) { - func() { - field := new(geom1) - deriveDeepCopy_8(field, &src.geom1) - dst.geom1 = *field - }() -} - -// deriveDeepCopy_5 recursively copies the contents of src into dst. -func deriveDeepCopy_5(dst, src *MultiPolygon) { - func() { - field := new(geom3) - deriveDeepCopy_10(field, &src.geom3) - dst.geom3 = *field - }() -} - -// deriveDeepCopy_6 recursively copies the contents of src into dst. -func deriveDeepCopy_6(dst, src *Point) { - func() { - field := new(geom0) - deriveDeepCopy_11(field, &src.geom0) - dst.geom0 = *field - }() -} - -// deriveDeepCopy_7 recursively copies the contents of src into dst. -func deriveDeepCopy_7(dst, src *Polygon) { - func() { - field := new(geom2) - deriveDeepCopy_9(field, &src.geom2) - dst.geom2 = *field - }() -} - -// deriveDeepCopy_8 recursively copies the contents of src into dst. -func deriveDeepCopy_8(dst, src *geom1) { - func() { - field := new(geom0) - deriveDeepCopy_11(field, &src.geom0) - dst.geom0 = *field - }() -} - -// deriveDeepCopy_9 recursively copies the contents of src into dst. -func deriveDeepCopy_9(dst, src *geom2) { - func() { - field := new(geom1) - deriveDeepCopy_8(field, &src.geom1) - dst.geom1 = *field - }() - if src.ends == nil { - dst.ends = nil - } else { - if dst.ends != nil { - if len(src.ends) > len(dst.ends) { - if cap(dst.ends) >= len(src.ends) { - dst.ends = (dst.ends)[:len(src.ends)] - } else { - dst.ends = make([]int, len(src.ends)) - } - } else if len(src.ends) < len(dst.ends) { - dst.ends = (dst.ends)[:len(src.ends)] - } - } else { - dst.ends = make([]int, len(src.ends)) - } - copy(dst.ends, src.ends) - } -} - -// deriveDeepCopy_10 recursively copies the contents of src into dst. -func deriveDeepCopy_10(dst, src *geom3) { - func() { - field := new(geom1) - deriveDeepCopy_8(field, &src.geom1) - dst.geom1 = *field - }() - if src.endss == nil { - dst.endss = nil - } else { - if dst.endss != nil { - if len(src.endss) > len(dst.endss) { - if cap(dst.endss) >= len(src.endss) { - dst.endss = (dst.endss)[:len(src.endss)] - } else { - dst.endss = make([][]int, len(src.endss)) - } - } else if len(src.endss) < len(dst.endss) { - dst.endss = (dst.endss)[:len(src.endss)] - } - } else { - dst.endss = make([][]int, len(src.endss)) - } - deriveDeepCopy_12(dst.endss, src.endss) - } -} - -// deriveDeepCopy_11 recursively copies the contents of src into dst. -func deriveDeepCopy_11(dst, src *geom0) { - dst.layout = src.layout - dst.stride = src.stride - if src.flatCoords == nil { - dst.flatCoords = nil - } else { - if dst.flatCoords != nil { - if len(src.flatCoords) > len(dst.flatCoords) { - if cap(dst.flatCoords) >= len(src.flatCoords) { - dst.flatCoords = (dst.flatCoords)[:len(src.flatCoords)] - } else { - dst.flatCoords = make([]float64, len(src.flatCoords)) - } - } else if len(src.flatCoords) < len(dst.flatCoords) { - dst.flatCoords = (dst.flatCoords)[:len(src.flatCoords)] - } - } else { - dst.flatCoords = make([]float64, len(src.flatCoords)) - } - copy(dst.flatCoords, src.flatCoords) - } - dst.srid = src.srid -} - -// deriveDeepCopy_12 recursively copies the contents of src into dst. -func deriveDeepCopy_12(dst, src [][]int) { - for src_i, src_value := range src { - if src_value == nil { - dst[src_i] = nil - } else { - if dst[src_i] != nil { - if len(src_value) > len(dst[src_i]) { - if cap(dst[src_i]) >= len(src_value) { - dst[src_i] = (dst[src_i])[:len(src_value)] - } else { - dst[src_i] = make([]int, len(src_value)) - } - } else if len(src_value) < len(dst[src_i]) { - dst[src_i] = (dst[src_i])[:len(src_value)] - } - } else { - dst[src_i] = make([]int, len(src_value)) - } - copy(dst[src_i], src_value) - } - } -} diff --git a/vendor/github.com/twpayne/go-geom/encoding/geojson/geojson.go b/vendor/github.com/twpayne/go-geom/encoding/geojson/geojson.go deleted file mode 100644 index 2e4771f..0000000 --- a/vendor/github.com/twpayne/go-geom/encoding/geojson/geojson.go +++ /dev/null @@ -1,353 +0,0 @@ -// Package geojson implements GeoJSON encoding and decoding. -package geojson - -import ( - "encoding/json" - "fmt" - - geom "github.com/twpayne/go-geom" -) - -// DefaultLayout is the default layout for empty geometries. -// FIXME This should be Codec-specific, not global -var DefaultLayout = geom.XY - -// ErrDimensionalityTooLow is returned when the dimensionality is too low. -type ErrDimensionalityTooLow int - -func (e ErrDimensionalityTooLow) Error() string { - return fmt.Sprintf("geojson: dimensionality too low (%d)", int(e)) -} - -// ErrUnsupportedType is returned when the type is unsupported. -type ErrUnsupportedType string - -func (e ErrUnsupportedType) Error() string { - return fmt.Sprintf("geojson: unsupported type: %s", string(e)) -} - -// A Geometry is a geometry in GeoJSON format. -type Geometry struct { - Type string `json:"type"` - Coordinates *json.RawMessage `json:"coordinates,omitempty"` - Geometries []*Geometry `json:"geometries,omitempty"` -} - -// A Feature is a GeoJSON Feature. -type Feature struct { - ID string - Geometry geom.T - Properties map[string]interface{} -} - -type geojsonFeature struct { - Type string `json:"type"` - ID string `json:"id,omitempty"` - Geometry *Geometry `json:"geometry"` - Properties map[string]interface{} `json:"properties"` -} - -// A FeatureCollection is a GeoJSON FeatureCollection. -type FeatureCollection struct { - Features []*Feature -} - -type geojsonFeatureCollection struct { - Type string `json:"type"` - Features []*Feature `json:"features"` -} - -func guessLayout0(coords0 []float64) (geom.Layout, error) { - switch n := len(coords0); n { - case 0, 1: - return geom.NoLayout, ErrDimensionalityTooLow(len(coords0)) - case 2: - return geom.XY, nil - case 3: - return geom.XYZ, nil - case 4: - return geom.XYZM, nil - default: - return geom.Layout(n), nil - } -} - -func guessLayout1(coords1 []geom.Coord) (geom.Layout, error) { - if len(coords1) == 0 { - return DefaultLayout, nil - } - return guessLayout0(coords1[0]) -} - -func guessLayout2(coords2 [][]geom.Coord) (geom.Layout, error) { - if len(coords2) == 0 { - return DefaultLayout, nil - } - return guessLayout1(coords2[0]) -} - -func guessLayout3(coords3 [][][]geom.Coord) (geom.Layout, error) { - if len(coords3) == 0 { - return DefaultLayout, nil - } - return guessLayout2(coords3[0]) -} - -// Decode decodes g to a geometry. -func (g *Geometry) Decode() (geom.T, error) { - switch g.Type { - case "Point": - if g.Coordinates == nil { - return geom.NewPoint(geom.NoLayout), nil - } - var coords geom.Coord - if err := json.Unmarshal(*g.Coordinates, &coords); err != nil { - return nil, err - } - layout, err := guessLayout0(coords) - if err != nil { - return nil, err - } - return geom.NewPoint(layout).SetCoords(coords) - case "LineString": - if g.Coordinates == nil { - return geom.NewLineString(geom.NoLayout), nil - } - var coords []geom.Coord - if err := json.Unmarshal(*g.Coordinates, &coords); err != nil { - return nil, err - } - layout, err := guessLayout1(coords) - if err != nil { - return nil, err - } - return geom.NewLineString(layout).SetCoords(coords) - case "Polygon": - if g.Coordinates == nil { - return geom.NewPolygon(geom.NoLayout), nil - } - var coords [][]geom.Coord - if err := json.Unmarshal(*g.Coordinates, &coords); err != nil { - return nil, err - } - layout, err := guessLayout2(coords) - if err != nil { - return nil, err - } - return geom.NewPolygon(layout).SetCoords(coords) - case "MultiPoint": - if g.Coordinates == nil { - return geom.NewMultiPoint(geom.NoLayout), nil - } - var coords []geom.Coord - if err := json.Unmarshal(*g.Coordinates, &coords); err != nil { - return nil, err - } - layout, err := guessLayout1(coords) - if err != nil { - return nil, err - } - return geom.NewMultiPoint(layout).SetCoords(coords) - case "MultiLineString": - if g.Coordinates == nil { - return geom.NewMultiLineString(geom.NoLayout), nil - } - var coords [][]geom.Coord - if err := json.Unmarshal(*g.Coordinates, &coords); err != nil { - return nil, err - } - layout, err := guessLayout2(coords) - if err != nil { - return nil, err - } - return geom.NewMultiLineString(layout).SetCoords(coords) - case "MultiPolygon": - if g.Coordinates == nil { - return geom.NewMultiPolygon(geom.NoLayout), nil - } - var coords [][][]geom.Coord - if err := json.Unmarshal(*g.Coordinates, &coords); err != nil { - return nil, err - } - layout, err := guessLayout3(coords) - if err != nil { - return nil, err - } - return geom.NewMultiPolygon(layout).SetCoords(coords) - case "GeometryCollection": - geoms := make([]geom.T, len(g.Geometries)) - for i, subGeometry := range g.Geometries { - var err error - geoms[i], err = subGeometry.Decode() - if err != nil { - return nil, err - } - } - gc := geom.NewGeometryCollection() - if err := gc.Push(geoms...); err != nil { - return nil, err - } - return gc, nil - default: - return nil, ErrUnsupportedType(g.Type) - } -} - -// Encode encodes g as a GeoJSON geometry. -func Encode(g geom.T) (*Geometry, error) { - switch g := g.(type) { - case *geom.Point: - var coords json.RawMessage - coords, err := json.Marshal(g.Coords()) - if err != nil { - return nil, err - } - return &Geometry{ - Type: "Point", - Coordinates: &coords, - }, nil - case *geom.LineString: - var coords json.RawMessage - coords, err := json.Marshal(g.Coords()) - if err != nil { - return nil, err - } - return &Geometry{ - Type: "LineString", - Coordinates: &coords, - }, nil - case *geom.Polygon: - var coords json.RawMessage - coords, err := json.Marshal(g.Coords()) - if err != nil { - return nil, err - } - return &Geometry{ - Type: "Polygon", - Coordinates: &coords, - }, nil - case *geom.MultiPoint: - var coords json.RawMessage - coords, err := json.Marshal(g.Coords()) - if err != nil { - return nil, err - } - return &Geometry{ - Type: "MultiPoint", - Coordinates: &coords, - }, nil - case *geom.MultiLineString: - var coords json.RawMessage - coords, err := json.Marshal(g.Coords()) - if err != nil { - return nil, err - } - return &Geometry{ - Type: "MultiLineString", - Coordinates: &coords, - }, nil - case *geom.MultiPolygon: - var coords json.RawMessage - coords, err := json.Marshal(g.Coords()) - if err != nil { - return nil, err - } - return &Geometry{ - Type: "MultiPolygon", - Coordinates: &coords, - }, nil - case *geom.GeometryCollection: - geometries := make([]*Geometry, len(g.Geoms())) - for i, subGeometry := range g.Geoms() { - var err error - geometries[i], err = Encode(subGeometry) - if err != nil { - return nil, err - } - } - return &Geometry{ - Type: "GeometryCollection", - Geometries: geometries, - }, nil - default: - return nil, geom.ErrUnsupportedType{Value: g} - } -} - -// Marshal marshals an arbitrary geometry to a []byte. -func Marshal(g geom.T) ([]byte, error) { - geojson, err := Encode(g) - if err != nil { - return nil, err - } - return json.Marshal(geojson) -} - -// Unmarshal unmarshalls a []byte to an arbitrary geometry. -func Unmarshal(data []byte, g *geom.T) error { - gg := &Geometry{} - if err := json.Unmarshal(data, gg); err != nil { - return err - } - var err error - *g, err = gg.Decode() - return err -} - -// MarshalJSON implements json.Marshaler.MarshalJSON. -func (f *Feature) MarshalJSON() ([]byte, error) { - geometry, err := Encode(f.Geometry) - if err != nil { - return nil, err - } - return json.Marshal(&geojsonFeature{ - ID: f.ID, - Type: "Feature", - Geometry: geometry, - Properties: f.Properties, - }) -} - -// UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON. -func (f *Feature) UnmarshalJSON(data []byte) error { - var gf geojsonFeature - if err := json.Unmarshal(data, &gf); err != nil { - return err - } - if gf.Type != "Feature" { - return ErrUnsupportedType(gf.Type) - } - f.ID = gf.ID - var err error - f.Geometry, err = gf.Geometry.Decode() - if err != nil { - return err - } - f.Properties = gf.Properties - return nil -} - -// MarshalJSON implements json.Marshaler.MarshalJSON. -func (fc *FeatureCollection) MarshalJSON() ([]byte, error) { - gfc := &geojsonFeatureCollection{ - Type: "FeatureCollection", - Features: fc.Features, - } - if gfc.Features == nil { - gfc.Features = []*Feature{} - } - return json.Marshal(gfc) -} - -// UnmarshalJSON implements json.Unmarshaler.UnmarshalJSON -func (fc *FeatureCollection) UnmarshalJSON(data []byte) error { - var gfc geojsonFeatureCollection - if err := json.Unmarshal(data, &gfc); err != nil { - return err - } - if gfc.Type != "FeatureCollection" { - return ErrUnsupportedType(gfc.Type) - } - fc.Features = gfc.Features - return nil -} diff --git a/vendor/github.com/twpayne/go-geom/encoding/wkt/wkt.go b/vendor/github.com/twpayne/go-geom/encoding/wkt/wkt.go deleted file mode 100644 index 7de8902..0000000 --- a/vendor/github.com/twpayne/go-geom/encoding/wkt/wkt.go +++ /dev/null @@ -1,189 +0,0 @@ -package wkt - -import ( - "bytes" - "strconv" - - "github.com/twpayne/go-geom" -) - -// Marshal marshals an arbitrary geometry. -func Marshal(g geom.T) (string, error) { - b := &bytes.Buffer{} - if err := write(b, g); err != nil { - return "", err - } - return b.String(), nil -} - -func write(b *bytes.Buffer, g geom.T) error { - typeString := "" - switch g := g.(type) { - case *geom.Point: - typeString = "POINT " - case *geom.LineString: - typeString = "LINESTRING " - case *geom.Polygon: - typeString = "POLYGON " - case *geom.MultiPoint: - typeString = "MULTIPOINT " - case *geom.MultiLineString: - typeString = "MULTILINESTRING " - case *geom.MultiPolygon: - typeString = "MULTIPOLYGON " - case *geom.GeometryCollection: - typeString = "GEOMETRYCOLLECTION " - default: - return geom.ErrUnsupportedType{Value: g} - } - layout := g.Layout() - switch layout { - case geom.NoLayout: - // Special case for empty GeometryCollections - if g, ok := g.(*geom.GeometryCollection); !ok || !g.Empty() { - return geom.ErrUnsupportedLayout(layout) - } - case geom.XY: - case geom.XYZ: - typeString += "Z " - case geom.XYM: - typeString += "M " - case geom.XYZM: - typeString += "ZM " - default: - return geom.ErrUnsupportedLayout(layout) - } - if _, err := b.WriteString(typeString); err != nil { - return err - } - switch g := g.(type) { - case *geom.Point: - return writeFlatCoords0(b, g.FlatCoords(), layout.Stride()) - case *geom.LineString: - return writeFlatCoords1(b, g.FlatCoords(), layout.Stride()) - case *geom.Polygon: - return writeFlatCoords2(b, g.FlatCoords(), 0, g.Ends(), layout.Stride()) - case *geom.MultiPoint: - if g.Empty() { - return writeEMPTY(b) - } - return writeFlatCoords1(b, g.FlatCoords(), layout.Stride()) - case *geom.MultiLineString: - if g.Empty() { - return writeEMPTY(b) - } - return writeFlatCoords2(b, g.FlatCoords(), 0, g.Ends(), layout.Stride()) - case *geom.MultiPolygon: - if g.Empty() { - return writeEMPTY(b) - } - return writeFlatCoords3(b, g.FlatCoords(), g.Endss(), layout.Stride()) - case *geom.GeometryCollection: - if g.Empty() { - return writeEMPTY(b) - } - if _, err := b.WriteRune('('); err != nil { - return err - } - for i, g := range g.Geoms() { - if i != 0 { - if _, err := b.WriteString(", "); err != nil { - return err - } - } - if err := write(b, g); err != nil { - return err - } - } - _, err := b.WriteRune(')') - return err - } - return nil -} - -func writeCoord(b *bytes.Buffer, coord []float64) error { - for i, x := range coord { - if i != 0 { - if _, err := b.WriteRune(' '); err != nil { - return err - } - } - if _, err := b.WriteString(strconv.FormatFloat(x, 'f', -1, 64)); err != nil { - return err - } - } - return nil -} - -func writeEMPTY(b *bytes.Buffer) error { - _, err := b.WriteString("EMPTY") - return err -} - -func writeFlatCoords0(b *bytes.Buffer, flatCoords []float64, stride int) error { - if _, err := b.WriteRune('('); err != nil { - return err - } - if err := writeCoord(b, flatCoords[:stride]); err != nil { - return err - } - _, err := b.WriteRune(')') - return err -} - -func writeFlatCoords1(b *bytes.Buffer, flatCoords []float64, stride int) error { - if _, err := b.WriteRune('('); err != nil { - return err - } - for i, n := 0, len(flatCoords); i < n; i += stride { - if i != 0 { - if _, err := b.WriteString(", "); err != nil { - return err - } - } - if err := writeCoord(b, flatCoords[i:i+stride]); err != nil { - return err - } - } - _, err := b.WriteRune(')') - return err -} - -func writeFlatCoords2(b *bytes.Buffer, flatCoords []float64, start int, ends []int, stride int) error { - if _, err := b.WriteRune('('); err != nil { - return err - } - for i, end := range ends { - if i != 0 { - if _, err := b.WriteString(", "); err != nil { - return err - } - } - if err := writeFlatCoords1(b, flatCoords[start:end], stride); err != nil { - return err - } - start = end - } - _, err := b.WriteRune(')') - return err -} - -func writeFlatCoords3(b *bytes.Buffer, flatCoords []float64, endss [][]int, stride int) error { - if _, err := b.WriteRune('('); err != nil { - return err - } - start := 0 - for i, ends := range endss { - if i != 0 { - if _, err := b.WriteString(", "); err != nil { - return err - } - } - if err := writeFlatCoords2(b, flatCoords, start, ends, stride); err != nil { - return err - } - start = ends[len(ends)-1] - } - _, err := b.WriteRune(')') - return err -} diff --git a/vendor/github.com/twpayne/go-geom/flat.go b/vendor/github.com/twpayne/go-geom/flat.go deleted file mode 100644 index 45b52bb..0000000 --- a/vendor/github.com/twpayne/go-geom/flat.go +++ /dev/null @@ -1,377 +0,0 @@ -package geom - -import "math" - -type geom0 struct { - layout Layout - stride int - flatCoords []float64 - srid int -} - -type geom1 struct { - geom0 -} - -type geom2 struct { - geom1 - ends []int -} - -type geom3 struct { - geom1 - endss [][]int -} - -// Bounds returns the bounds of g. -func (g *geom0) Bounds() *Bounds { - return NewBounds(g.layout).extendFlatCoords(g.flatCoords, 0, len(g.flatCoords), g.stride) -} - -// Coords returns all the coordinates in g, i.e. a single coordinate. -func (g *geom0) Coords() Coord { - return inflate0(g.flatCoords, 0, len(g.flatCoords), g.stride) -} - -// Ends returns the end indexes of sub-structures of g, i.e. an empty slice. -func (g *geom0) Ends() []int { - return nil -} - -// Endss returns the end indexes of sub-sub-structures of g, i.e. an empty -// slice. -func (g *geom0) Endss() [][]int { - return nil -} - -// FlatCoords returns the flat coordinates of g. -func (g *geom0) FlatCoords() []float64 { - return g.flatCoords -} - -// Layout returns g's layout. -func (g *geom0) Layout() Layout { - return g.layout -} - -// NumCoords returns the number of coordinates in g, i.e. 1. -func (g *geom0) NumCoords() int { - return 1 -} - -// Reserve reserves space in g for n coordinates. -func (g *geom0) Reserve(n int) { - if cap(g.flatCoords) < n*g.stride { - fcs := make([]float64, len(g.flatCoords), n*g.stride) - copy(fcs, g.flatCoords) - g.flatCoords = fcs - } -} - -// SRID returns g's SRID. -func (g *geom0) SRID() int { - return g.srid -} - -func (g *geom0) setCoords(coords0 []float64) error { - var err error - g.flatCoords, err = deflate0(nil, coords0, g.stride) - return err -} - -// Stride returns g's stride. -func (g *geom0) Stride() int { - return g.stride -} - -func (g *geom0) verify() error { - if g.stride != g.layout.Stride() { - return errStrideLayoutMismatch - } - if g.stride == 0 { - if len(g.flatCoords) != 0 { - return errNonEmptyFlatCoords - } - return nil - } - if len(g.flatCoords) != g.stride { - return errLengthStrideMismatch - } - return nil -} - -// Coord returns the ith coord of g. -func (g *geom1) Coord(i int) Coord { - return g.flatCoords[i*g.stride : (i+1)*g.stride] -} - -// Coords unpacks and returns all of g's coordinates. -func (g *geom1) Coords() []Coord { - return inflate1(g.flatCoords, 0, len(g.flatCoords), g.stride) -} - -// NumCoords returns the number of coordinates in g. -func (g *geom1) NumCoords() int { - return len(g.flatCoords) / g.stride -} - -func (g *geom1) setCoords(coords1 []Coord) error { - var err error - g.flatCoords, err = deflate1(nil, coords1, g.stride) - return err -} - -func (g *geom1) verify() error { - if g.stride != g.layout.Stride() { - return errStrideLayoutMismatch - } - if g.stride == 0 { - if len(g.flatCoords) != 0 { - return errNonEmptyFlatCoords - } - } else { - if len(g.flatCoords)%g.stride != 0 { - return errLengthStrideMismatch - } - } - return nil -} - -// Coords returns all of g's coordinates. -func (g *geom2) Coords() [][]Coord { - return inflate2(g.flatCoords, 0, g.ends, g.stride) -} - -// Ends returns the end indexes of all sub-structures in g. -func (g *geom2) Ends() []int { - return g.ends -} - -func (g *geom2) setCoords(coords2 [][]Coord) error { - var err error - g.flatCoords, g.ends, err = deflate2(nil, nil, coords2, g.stride) - return err -} - -func (g *geom2) verify() error { - if g.stride != g.layout.Stride() { - return errStrideLayoutMismatch - } - if g.stride == 0 { - if len(g.flatCoords) != 0 { - return errNonEmptyFlatCoords - } - if len(g.ends) != 0 { - return errNonEmptyEnds - } - return nil - } - if len(g.flatCoords)%g.stride != 0 { - return errLengthStrideMismatch - } - offset := 0 - for _, end := range g.ends { - if end%g.stride != 0 { - return errMisalignedEnd - } - if end < offset { - return errOutOfOrderEnd - } - offset = end - } - if offset != len(g.flatCoords) { - return errIncorrectEnd - } - return nil -} - -// Coords returns all the coordinates in g. -func (g *geom3) Coords() [][][]Coord { - return inflate3(g.flatCoords, 0, g.endss, g.stride) -} - -// Endss returns a list of all the sub-sub-structures in g. -func (g *geom3) Endss() [][]int { - return g.endss -} - -func (g *geom3) setCoords(coords3 [][][]Coord) error { - var err error - g.flatCoords, g.endss, err = deflate3(nil, nil, coords3, g.stride) - return err -} - -func (g *geom3) verify() error { - if g.stride != g.layout.Stride() { - return errStrideLayoutMismatch - } - if g.stride == 0 { - if len(g.flatCoords) != 0 { - return errNonEmptyFlatCoords - } - if len(g.endss) != 0 { - return errNonEmptyEndss - } - return nil - } - if len(g.flatCoords)%g.stride != 0 { - return errLengthStrideMismatch - } - offset := 0 - for _, ends := range g.endss { - for _, end := range ends { - if end%g.stride != 0 { - return errMisalignedEnd - } - if end < offset { - return errOutOfOrderEnd - } - offset = end - } - } - if offset != len(g.flatCoords) { - return errIncorrectEnd - } - return nil -} - -func doubleArea1(flatCoords []float64, offset, end, stride int) float64 { - var doubleArea float64 - for i := offset + stride; i < end; i += stride { - doubleArea += (flatCoords[i+1] - flatCoords[i+1-stride]) * (flatCoords[i] + flatCoords[i-stride]) - } - return doubleArea -} - -func doubleArea2(flatCoords []float64, offset int, ends []int, stride int) float64 { - var doubleArea float64 - for i, end := range ends { - da := doubleArea1(flatCoords, offset, end, stride) - if i == 0 { - doubleArea = da - } else { - doubleArea -= da - } - offset = end - } - return doubleArea -} - -func doubleArea3(flatCoords []float64, offset int, endss [][]int, stride int) float64 { - var doubleArea float64 - for _, ends := range endss { - doubleArea += doubleArea2(flatCoords, offset, ends, stride) - offset = ends[len(ends)-1] - } - return doubleArea -} - -func deflate0(flatCoords []float64, c Coord, stride int) ([]float64, error) { - if len(c) != stride { - return nil, ErrStrideMismatch{Got: len(c), Want: stride} - } - flatCoords = append(flatCoords, c...) - return flatCoords, nil -} - -func deflate1(flatCoords []float64, coords1 []Coord, stride int) ([]float64, error) { - for _, c := range coords1 { - var err error - flatCoords, err = deflate0(flatCoords, c, stride) - if err != nil { - return nil, err - } - } - return flatCoords, nil -} - -func deflate2(flatCoords []float64, ends []int, coords2 [][]Coord, stride int) ([]float64, []int, error) { - for _, coords1 := range coords2 { - var err error - flatCoords, err = deflate1(flatCoords, coords1, stride) - if err != nil { - return nil, nil, err - } - ends = append(ends, len(flatCoords)) - } - return flatCoords, ends, nil -} - -func deflate3(flatCoords []float64, endss [][]int, coords3 [][][]Coord, stride int) ([]float64, [][]int, error) { - for _, coords2 := range coords3 { - var err error - var ends []int - flatCoords, ends, err = deflate2(flatCoords, ends, coords2, stride) - if err != nil { - return nil, nil, err - } - endss = append(endss, ends) - } - return flatCoords, endss, nil -} - -func inflate0(flatCoords []float64, offset, end, stride int) Coord { - if offset+stride != end { - panic("geom: stride mismatch") - } - c := make([]float64, stride) - copy(c, flatCoords[offset:end]) - return c -} - -func inflate1(flatCoords []float64, offset, end, stride int) []Coord { - coords1 := make([]Coord, (end-offset)/stride) - for i := range coords1 { - coords1[i] = inflate0(flatCoords, offset, offset+stride, stride) - offset += stride - } - return coords1 -} - -func inflate2(flatCoords []float64, offset int, ends []int, stride int) [][]Coord { - coords2 := make([][]Coord, len(ends)) - for i := range coords2 { - end := ends[i] - coords2[i] = inflate1(flatCoords, offset, end, stride) - offset = end - } - return coords2 -} - -func inflate3(flatCoords []float64, offset int, endss [][]int, stride int) [][][]Coord { - coords3 := make([][][]Coord, len(endss)) - for i := range coords3 { - ends := endss[i] - coords3[i] = inflate2(flatCoords, offset, ends, stride) - offset = ends[len(ends)-1] - } - return coords3 -} - -func length1(flatCoords []float64, offset, end, stride int) float64 { - var length float64 - for i := offset + stride; i < end; i += stride { - dx := flatCoords[i] - flatCoords[i-stride] - dy := flatCoords[i+1] - flatCoords[i+1-stride] - length += math.Sqrt(dx*dx + dy*dy) - } - return length -} - -func length2(flatCoords []float64, offset int, ends []int, stride int) float64 { - var length float64 - for _, end := range ends { - length += length1(flatCoords, offset, end, stride) - offset = end - } - return length -} - -func length3(flatCoords []float64, offset int, endss [][]int, stride int) float64 { - var length float64 - for _, ends := range endss { - length += length2(flatCoords, offset, ends, stride) - offset = ends[len(ends)-1] - } - return length -} diff --git a/vendor/github.com/twpayne/go-geom/geom.go b/vendor/github.com/twpayne/go-geom/geom.go deleted file mode 100644 index 08e15f2..0000000 --- a/vendor/github.com/twpayne/go-geom/geom.go +++ /dev/null @@ -1,212 +0,0 @@ -// Package geom implements efficient geometry types for geospatial -// applications. -package geom - -//go:generate goderive . - -import ( - "errors" - "fmt" - "math" -) - -// A Layout describes the meaning of an N-dimensional coordinate. Layout(N) for -// N > 4 is a valid layout, in which case the first dimensions are interpreted -// to be X, Y, Z, and M and extra dimensions have no special meaning. M values -// are considered part of a linear referencing system (e.g. classical time or -// distance along a path). 1-dimensional layouts are not supported. -type Layout int - -const ( - // NoLayout is an unknown layout - NoLayout Layout = iota - // XY is a 2D layout (X and Y) - XY - // XYZ is 3D layout (X, Y, and Z) - XYZ - // XYM is a 2D layout with an M value - XYM - // XYZM is a 3D layout with an M value - XYZM -) - -// An ErrLayoutMismatch is returned when geometries with different layouts -// cannot be combined. -type ErrLayoutMismatch struct { - Got Layout - Want Layout -} - -func (e ErrLayoutMismatch) Error() string { - return fmt.Sprintf("geom: layout mismatch, got %s, want %s", e.Got, e.Want) -} - -// An ErrStrideMismatch is returned when the stride does not match the expected -// stride. -type ErrStrideMismatch struct { - Got int - Want int -} - -func (e ErrStrideMismatch) Error() string { - return fmt.Sprintf("geom: stride mismatch, got %d, want %d", e.Got, e.Want) -} - -// An ErrUnsupportedLayout is returned when the requested layout is not -// supported. -type ErrUnsupportedLayout Layout - -func (e ErrUnsupportedLayout) Error() string { - return fmt.Sprintf("geom: unsupported layout %s", Layout(e)) -} - -// An ErrUnsupportedType is returned when the requested type is not supported. -type ErrUnsupportedType struct { - Value interface{} -} - -func (e ErrUnsupportedType) Error() string { - return fmt.Sprintf("geom: unsupported type %T", e.Value) -} - -// A Coord represents an N-dimensional coordinate. -type Coord []float64 - -// Clone returns a deep copy of c. -func (c Coord) Clone() Coord { - return deriveCloneCoord(c) -} - -// X returns the x coordinate of c. X is assumed to be the first ordinate. -func (c Coord) X() float64 { - return c[0] -} - -// Y returns the y coordinate of c. Y is assumed to be the second ordinate. -func (c Coord) Y() float64 { - return c[1] -} - -// Set copies the ordinate data from the other coord to this coord. -func (c Coord) Set(other Coord) { - copy(c, other) -} - -// Equal compares that all ordinates are the same in this and the other coords. -// It is assumed that this coord and other coord both have the same (provided) -// layout. -func (c Coord) Equal(layout Layout, other Coord) bool { - numOrds := len(c) - - if layout.Stride() < numOrds { - numOrds = layout.Stride() - } - - if (len(c) < layout.Stride() || len(other) < layout.Stride()) && len(c) != len(other) { - return false - } - - for i := 0; i < numOrds; i++ { - if math.IsNaN(c[i]) || math.IsNaN(other[i]) { - if !math.IsNaN(c[i]) || !math.IsNaN(other[i]) { - return false - } - } else if c[i] != other[i] { - return false - } - } - - return true -} - -// T is a generic interface implemented by all geometry types. -type T interface { - Layout() Layout - Stride() int - Bounds() *Bounds - FlatCoords() []float64 - Ends() []int - Endss() [][]int - SRID() int -} - -// MIndex returns the index of the M dimension, or -1 if the l does not have an -// M dimension. -func (l Layout) MIndex() int { - switch l { - case NoLayout, XY, XYZ: - return -1 - case XYM: - return 2 - case XYZM: - return 3 - default: - return 3 - } -} - -// Stride returns l's number of dimensions. -func (l Layout) Stride() int { - switch l { - case NoLayout: - return 0 - case XY: - return 2 - case XYZ: - return 3 - case XYM: - return 3 - case XYZM: - return 4 - default: - return int(l) - } -} - -// String returns a human-readable string representing l. -func (l Layout) String() string { - switch l { - case NoLayout: - return "NoLayout" - case XY: - return "XY" - case XYZ: - return "XYZ" - case XYM: - return "XYM" - case XYZM: - return "XYZM" - default: - return fmt.Sprintf("Layout(%d)", int(l)) - } -} - -// ZIndex returns the index of l's Z dimension, or -1 if l does not have a Z -// dimension. -func (l Layout) ZIndex() int { - switch l { - case NoLayout, XY, XYM: - return -1 - default: - return 2 - } -} - -// Must panics if err is not nil, otherwise it returns g. -func Must(g T, err error) T { - if err != nil { - panic(err) - } - return g -} - -var ( - errIncorrectEnd = errors.New("geom: incorrect end") - errLengthStrideMismatch = errors.New("geom: length/stride mismatch") - errMisalignedEnd = errors.New("geom: misaligned end") - errNonEmptyEnds = errors.New("geom: non-empty ends") - errNonEmptyEndss = errors.New("geom: non-empty endss") - errNonEmptyFlatCoords = errors.New("geom: non-empty flatCoords") - errOutOfOrderEnd = errors.New("geom: out-of-order end") - errStrideLayoutMismatch = errors.New("geom: stride/layout mismatch") -) diff --git a/vendor/github.com/twpayne/go-geom/geometrycollection.go b/vendor/github.com/twpayne/go-geom/geometrycollection.go deleted file mode 100644 index ef7bfd3..0000000 --- a/vendor/github.com/twpayne/go-geom/geometrycollection.go +++ /dev/null @@ -1,115 +0,0 @@ -package geom - -// A GeometryCollection is a collection of arbitrary geometries with the same -// SRID. -type GeometryCollection struct { - geoms []T - srid int -} - -// NewGeometryCollection returns a new empty GeometryCollection. -func NewGeometryCollection() *GeometryCollection { - return &GeometryCollection{} -} - -// Geom returns the ith geometry in g. -func (g *GeometryCollection) Geom(i int) T { - return g.geoms[i] -} - -// Geoms returns the geometries in g. -func (g *GeometryCollection) Geoms() []T { - return g.geoms -} - -// Layout returns the smallest layout that covers all of the layouts in g's -// geometries. -func (g *GeometryCollection) Layout() Layout { - maxLayout := NoLayout - for _, g := range g.geoms { - switch l := g.Layout(); l { - case XYZ: - if maxLayout == XYM { - maxLayout = XYZM - } else if l > maxLayout { - maxLayout = l - } - case XYM: - if maxLayout == XYZ { - maxLayout = XYZM - } else if l > maxLayout { - maxLayout = l - } - default: - if l > maxLayout { - maxLayout = l - } - } - } - return maxLayout -} - -// NumGeoms returns the number of geometries in g. -func (g *GeometryCollection) NumGeoms() int { - return len(g.geoms) -} - -// Stride returns the stride of g's layout. -func (g *GeometryCollection) Stride() int { - return g.Layout().Stride() -} - -// Bounds returns the bounds of all the geometries in g. -func (g *GeometryCollection) Bounds() *Bounds { - // FIXME this needs work for mixing layouts, e.g. XYZ and XYM - b := NewBounds(g.Layout()) - for _, g := range g.geoms { - b = b.Extend(g) - } - return b -} - -// Empty returns true if the collection is empty. -func (g *GeometryCollection) Empty() bool { - return len(g.geoms) == 0 -} - -// FlatCoords panics. -func (g *GeometryCollection) FlatCoords() []float64 { - panic("FlatCoords() called on a GeometryCollection") -} - -// Ends panics. -func (g *GeometryCollection) Ends() []int { - panic("Ends() called on a GeometryCollection") -} - -// Endss panics. -func (g *GeometryCollection) Endss() [][]int { - panic("Endss() called on a GeometryCollection") -} - -// SRID returns g's SRID. -func (g *GeometryCollection) SRID() int { - return g.srid -} - -// MustPush pushes gs to g. It panics on any error. -func (g *GeometryCollection) MustPush(gs ...T) *GeometryCollection { - if err := g.Push(gs...); err != nil { - panic(err) - } - return g -} - -// Push appends geometries. -func (g *GeometryCollection) Push(gs ...T) error { - g.geoms = append(g.geoms, gs...) - return nil -} - -// SetSRID sets g's SRID and the SRID of all its elements. -func (g *GeometryCollection) SetSRID(srid int) *GeometryCollection { - g.srid = srid - return g -} diff --git a/vendor/github.com/twpayne/go-geom/go.mod b/vendor/github.com/twpayne/go-geom/go.mod deleted file mode 100644 index 1ade2f5..0000000 --- a/vendor/github.com/twpayne/go-geom/go.mod +++ /dev/null @@ -1,22 +0,0 @@ -module github.com/twpayne/go-geom - -require ( - github.com/DATA-DOG/go-sqlmock v1.3.2 - github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect - github.com/cenkalti/backoff v2.1.1+incompatible // indirect - github.com/containerd/continuity v0.0.0-20181203112020-004b46473808 // indirect - github.com/d4l3k/messagediff v1.2.1 - github.com/docker/go-connections v0.4.0 // indirect - github.com/docker/go-units v0.3.3 // indirect - github.com/lib/pq v1.0.0 - github.com/opencontainers/go-digest v1.0.0-rc1 // indirect - github.com/opencontainers/image-spec v1.0.1 // indirect - github.com/opencontainers/runc v0.1.1 // indirect - github.com/ory/dockertest v3.3.4+incompatible - github.com/pkg/errors v0.8.1 // indirect - github.com/sirupsen/logrus v1.4.1 // indirect - github.com/stretchr/testify v1.3.0 - github.com/twpayne/go-kml v1.0.0 - golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 // indirect - golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 // indirect -) diff --git a/vendor/github.com/twpayne/go-geom/go.sum b/vendor/github.com/twpayne/go-geom/go.sum deleted file mode 100644 index 2d726ba..0000000 --- a/vendor/github.com/twpayne/go-geom/go.sum +++ /dev/null @@ -1,51 +0,0 @@ -github.com/DATA-DOG/go-sqlmock v1.3.2 h1:2L2f5t3kKnCLxnClDD/PrDfExFFa1wjESgxHG/B1ibo= -github.com/DATA-DOG/go-sqlmock v1.3.2/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= -github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= -github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= -github.com/cenkalti/backoff v2.1.1+incompatible h1:tKJnvO2kl0zmb/jA5UKAt4VoEVw1qxKWjE/Bpp46npY= -github.com/cenkalti/backoff v2.1.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= -github.com/containerd/continuity v0.0.0-20181203112020-004b46473808 h1:4BX8f882bXEDKfWIf0wa8HRvpnBoPszJJXL+TVbBw4M= -github.com/containerd/continuity v0.0.0-20181203112020-004b46473808/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y= -github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U= -github.com/d4l3k/messagediff v1.2.1/go.mod h1:Oozbb1TVXFac9FtSIxHBMnBCq2qeH/2KkEQxENCrlLo= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= -github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= -github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk= -github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A= -github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= -github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= -github.com/opencontainers/image-spec v1.0.1 h1:JMemWkRwHx4Zj+fVxWoMCFm/8sYGGrUVojFA6h/TRcI= -github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= -github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJGY8Y= -github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= -github.com/ory/dockertest v3.3.4+incompatible h1:VrpM6Gqg7CrPm3bL4Wm1skO+zFWLbh7/Xb5kGEbJRh8= -github.com/ory/dockertest v3.3.4+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k= -github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/twpayne/go-kml v1.0.0 h1:XMyRRufIWOYaPGW1UzTnqJO42oY7wngXyO7kW/vzXjI= -github.com/twpayne/go-kml v1.0.0/go.mod h1:LlvLIQSfMqYk2O7Nx8vYAbSLv4K9rjMvLlEdUKWdjq0= -github.com/twpayne/go-polyline v1.0.0/go.mod h1:ICh24bcLYBX8CknfvNPKqoTbe+eg+MX1NPyJmSBo7pU= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 h1:1Fzlr8kkDLQwqMP8GxrhptBLqZG/EDpiATneiZHY998= -golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/vendor/github.com/twpayne/go-geom/linearring.go b/vendor/github.com/twpayne/go-geom/linearring.go deleted file mode 100644 index 0009a1a..0000000 --- a/vendor/github.com/twpayne/go-geom/linearring.go +++ /dev/null @@ -1,65 +0,0 @@ -package geom - -// A LinearRing is a linear ring. -type LinearRing struct { - geom1 -} - -// NewLinearRing returns a new LinearRing with no coordinates. -func NewLinearRing(layout Layout) *LinearRing { - return NewLinearRingFlat(layout, nil) -} - -// NewLinearRingFlat returns a new LinearRing with the given flat coordinates. -func NewLinearRingFlat(layout Layout, flatCoords []float64) *LinearRing { - g := new(LinearRing) - g.layout = layout - g.stride = layout.Stride() - g.flatCoords = flatCoords - return g -} - -// Area returns the the area. -func (g *LinearRing) Area() float64 { - return doubleArea1(g.flatCoords, 0, len(g.flatCoords), g.stride) / 2 -} - -// Clone returns a deep copy. -func (g *LinearRing) Clone() *LinearRing { - return deriveCloneLinearRing(g) -} - -// Empty returns false. -func (g *LinearRing) Empty() bool { - return false -} - -// Length returns the length of the perimeter. -func (g *LinearRing) Length() float64 { - return length1(g.flatCoords, 0, len(g.flatCoords), g.stride) -} - -// MustSetCoords sets the coordinates and panics if there is any error. -func (g *LinearRing) MustSetCoords(coords []Coord) *LinearRing { - Must(g.SetCoords(coords)) - return g -} - -// SetCoords sets the coordinates. -func (g *LinearRing) SetCoords(coords []Coord) (*LinearRing, error) { - if err := g.setCoords(coords); err != nil { - return nil, err - } - return g, nil -} - -// SetSRID sets the SRID of g. -func (g *LinearRing) SetSRID(srid int) *LinearRing { - g.srid = srid - return g -} - -// Swap swaps the values of g and g2. -func (g *LinearRing) Swap(g2 *LinearRing) { - *g, *g2 = *g2, *g -} diff --git a/vendor/github.com/twpayne/go-geom/linestring.go b/vendor/github.com/twpayne/go-geom/linestring.go deleted file mode 100644 index e0434fe..0000000 --- a/vendor/github.com/twpayne/go-geom/linestring.go +++ /dev/null @@ -1,104 +0,0 @@ -package geom - -// A LineString represents a single, unbroken line, linearly interpreted -// between zero or more control points. -type LineString struct { - geom1 -} - -// NewLineString returns a new LineString with layout l and no control points. -func NewLineString(l Layout) *LineString { - return NewLineStringFlat(l, nil) -} - -// NewLineStringFlat returns a new LineString with layout l and control points -// flatCoords. -func NewLineStringFlat(layout Layout, flatCoords []float64) *LineString { - g := new(LineString) - g.layout = layout - g.stride = layout.Stride() - g.flatCoords = flatCoords - return g -} - -// Area returns the area of g, i.e. zero. -func (g *LineString) Area() float64 { - return 0 -} - -// Clone returns a copy of g that does not alias g. -func (g *LineString) Clone() *LineString { - return deriveCloneLineString(g) -} - -// Empty returns false. -func (g *LineString) Empty() bool { - return false -} - -// Interpolate returns the index and delta of val in dimension dim. -func (g *LineString) Interpolate(val float64, dim int) (int, float64) { - n := len(g.flatCoords) - if n == 0 { - panic("geom: empty linestring") - } - if val <= g.flatCoords[dim] { - return 0, 0 - } - if g.flatCoords[n-g.stride+dim] <= val { - return (n - 1) / g.stride, 0 - } - low := 0 - high := n / g.stride - for low < high { - mid := (low + high) / 2 - if val < g.flatCoords[mid*g.stride+dim] { - high = mid - } else { - low = mid + 1 - } - } - low-- - val0 := g.flatCoords[low*g.stride+dim] - if val == val0 { - return low, 0 - } - val1 := g.flatCoords[(low+1)*g.stride+dim] - return low, (val - val0) / (val1 - val0) -} - -// Length returns the length of g. -func (g *LineString) Length() float64 { - return length1(g.flatCoords, 0, len(g.flatCoords), g.stride) -} - -// MustSetCoords is like SetCoords but it panics on any error. -func (g *LineString) MustSetCoords(coords []Coord) *LineString { - Must(g.SetCoords(coords)) - return g -} - -// SetCoords sets the coordinates of g. -func (g *LineString) SetCoords(coords []Coord) (*LineString, error) { - if err := g.setCoords(coords); err != nil { - return nil, err - } - return g, nil -} - -// SetSRID sets the SRID of g. -func (g *LineString) SetSRID(srid int) *LineString { - g.srid = srid - return g -} - -// SubLineString returns a LineString from starts at index start and stops at -// index stop of g. The returned LineString aliases g. -func (g *LineString) SubLineString(start, stop int) *LineString { - return NewLineStringFlat(g.layout, g.flatCoords[start*g.stride:stop*g.stride]) -} - -// Swap swaps the values of g and g2. -func (g *LineString) Swap(g2 *LineString) { - *g, *g2 = *g2, *g -} diff --git a/vendor/github.com/twpayne/go-geom/multilinestring.go b/vendor/github.com/twpayne/go-geom/multilinestring.go deleted file mode 100644 index 597e4d0..0000000 --- a/vendor/github.com/twpayne/go-geom/multilinestring.go +++ /dev/null @@ -1,90 +0,0 @@ -package geom - -// A MultiLineString is a collection of LineStrings. -type MultiLineString struct { - geom2 -} - -// NewMultiLineString returns a new MultiLineString with no LineStrings. -func NewMultiLineString(layout Layout) *MultiLineString { - return NewMultiLineStringFlat(layout, nil, nil) -} - -// NewMultiLineStringFlat returns a new MultiLineString with the given flat coordinates. -func NewMultiLineStringFlat(layout Layout, flatCoords []float64, ends []int) *MultiLineString { - g := new(MultiLineString) - g.layout = layout - g.stride = layout.Stride() - g.flatCoords = flatCoords - g.ends = ends - return g -} - -// Area returns the area of g, i.e. 0. -func (g *MultiLineString) Area() float64 { - return 0 -} - -// Clone returns a deep copy. -func (g *MultiLineString) Clone() *MultiLineString { - return deriveCloneMultiLineString(g) -} - -// Empty returns true if the collection is empty. -func (g *MultiLineString) Empty() bool { - return g.NumLineStrings() == 0 -} - -// Length returns the sum of the length of the LineStrings. -func (g *MultiLineString) Length() float64 { - return length2(g.flatCoords, 0, g.ends, g.stride) -} - -// LineString returns the ith LineString. -func (g *MultiLineString) LineString(i int) *LineString { - offset := 0 - if i > 0 { - offset = g.ends[i-1] - } - return NewLineStringFlat(g.layout, g.flatCoords[offset:g.ends[i]]) -} - -// MustSetCoords sets the coordinates and panics on any error. -func (g *MultiLineString) MustSetCoords(coords [][]Coord) *MultiLineString { - Must(g.SetCoords(coords)) - return g -} - -// NumLineStrings returns the number of LineStrings. -func (g *MultiLineString) NumLineStrings() int { - return len(g.ends) -} - -// Push appends a LineString. -func (g *MultiLineString) Push(ls *LineString) error { - if ls.layout != g.layout { - return ErrLayoutMismatch{Got: ls.layout, Want: g.layout} - } - g.flatCoords = append(g.flatCoords, ls.flatCoords...) - g.ends = append(g.ends, len(g.flatCoords)) - return nil -} - -// SetCoords sets the coordinates. -func (g *MultiLineString) SetCoords(coords [][]Coord) (*MultiLineString, error) { - if err := g.setCoords(coords); err != nil { - return nil, err - } - return g, nil -} - -// SetSRID sets the SRID of g. -func (g *MultiLineString) SetSRID(srid int) *MultiLineString { - g.srid = srid - return g -} - -// Swap swaps the values of g and g2. -func (g *MultiLineString) Swap(g2 *MultiLineString) { - *g, *g2 = *g2, *g -} diff --git a/vendor/github.com/twpayne/go-geom/multipoint.go b/vendor/github.com/twpayne/go-geom/multipoint.go deleted file mode 100644 index bd1e0db..0000000 --- a/vendor/github.com/twpayne/go-geom/multipoint.go +++ /dev/null @@ -1,84 +0,0 @@ -package geom - -// A MultiPoint is a collection of Points. -type MultiPoint struct { - geom1 -} - -// NewMultiPoint returns a new, empty, MultiPoint. -func NewMultiPoint(layout Layout) *MultiPoint { - return NewMultiPointFlat(layout, nil) -} - -// NewMultiPointFlat returns a new MultiPoint with the given flat coordinates. -func NewMultiPointFlat(layout Layout, flatCoords []float64) *MultiPoint { - g := new(MultiPoint) - g.layout = layout - g.stride = layout.Stride() - g.flatCoords = flatCoords - return g -} - -// Area returns the area of g, i.e. zero. -func (g *MultiPoint) Area() float64 { - return 0 -} - -// Clone returns a deep copy. -func (g *MultiPoint) Clone() *MultiPoint { - return deriveCloneMultiPoint(g) -} - -// Empty returns true if the collection is empty. -func (g *MultiPoint) Empty() bool { - return g.NumPoints() == 0 -} - -// Length returns zero. -func (g *MultiPoint) Length() float64 { - return 0 -} - -// MustSetCoords sets the coordinates and panics on any error. -func (g *MultiPoint) MustSetCoords(coords []Coord) *MultiPoint { - Must(g.SetCoords(coords)) - return g -} - -// SetCoords sets the coordinates. -func (g *MultiPoint) SetCoords(coords []Coord) (*MultiPoint, error) { - if err := g.setCoords(coords); err != nil { - return nil, err - } - return g, nil -} - -// SetSRID sets the SRID of g. -func (g *MultiPoint) SetSRID(srid int) *MultiPoint { - g.srid = srid - return g -} - -// NumPoints returns the number of Points. -func (g *MultiPoint) NumPoints() int { - return g.NumCoords() -} - -// Point returns the ith Point. -func (g *MultiPoint) Point(i int) *Point { - return NewPointFlat(g.layout, g.Coord(i)) -} - -// Push appends a point. -func (g *MultiPoint) Push(p *Point) error { - if p.layout != g.layout { - return ErrLayoutMismatch{Got: p.layout, Want: g.layout} - } - g.flatCoords = append(g.flatCoords, p.flatCoords...) - return nil -} - -// Swap swaps the values of g and g2. -func (g *MultiPoint) Swap(g2 *MultiPoint) { - *g, *g2 = *g2, *g -} diff --git a/vendor/github.com/twpayne/go-geom/multipolygon.go b/vendor/github.com/twpayne/go-geom/multipolygon.go deleted file mode 100644 index 51ee06b..0000000 --- a/vendor/github.com/twpayne/go-geom/multipolygon.go +++ /dev/null @@ -1,108 +0,0 @@ -package geom - -// A MultiPolygon is a collection of Polygons. -type MultiPolygon struct { - geom3 -} - -// NewMultiPolygon returns a new MultiPolygon with no Polygons. -func NewMultiPolygon(layout Layout) *MultiPolygon { - return NewMultiPolygonFlat(layout, nil, nil) -} - -// NewMultiPolygonFlat returns a new MultiPolygon with the given flat coordinates. -func NewMultiPolygonFlat(layout Layout, flatCoords []float64, endss [][]int) *MultiPolygon { - g := new(MultiPolygon) - g.layout = layout - g.stride = layout.Stride() - g.flatCoords = flatCoords - g.endss = endss - return g -} - -// Area returns the sum of the area of the individual Polygons. -func (g *MultiPolygon) Area() float64 { - return doubleArea3(g.flatCoords, 0, g.endss, g.stride) / 2 -} - -// Clone returns a deep copy. -func (g *MultiPolygon) Clone() *MultiPolygon { - return deriveCloneMultiPolygon(g) -} - -// Empty returns true if the collection is empty. -func (g *MultiPolygon) Empty() bool { - return g.NumPolygons() == 0 -} - -// Length returns the sum of the perimeters of the Polygons. -func (g *MultiPolygon) Length() float64 { - return length3(g.flatCoords, 0, g.endss, g.stride) -} - -// MustSetCoords sets the coordinates and panics on any error. -func (g *MultiPolygon) MustSetCoords(coords [][][]Coord) *MultiPolygon { - Must(g.SetCoords(coords)) - return g -} - -// NumPolygons returns the number of Polygons. -func (g *MultiPolygon) NumPolygons() int { - return len(g.endss) -} - -// Polygon returns the ith Polygon. -func (g *MultiPolygon) Polygon(i int) *Polygon { - offset := 0 - if i > 0 { - ends := g.endss[i-1] - offset = ends[len(ends)-1] - } - ends := make([]int, len(g.endss[i])) - if offset == 0 { - copy(ends, g.endss[i]) - } else { - for j, end := range g.endss[i] { - ends[j] = end - offset - } - } - return NewPolygonFlat(g.layout, g.flatCoords[offset:g.endss[i][len(g.endss[i])-1]], ends) -} - -// Push appends a Polygon. -func (g *MultiPolygon) Push(p *Polygon) error { - if p.layout != g.layout { - return ErrLayoutMismatch{Got: p.layout, Want: g.layout} - } - offset := len(g.flatCoords) - ends := make([]int, len(p.ends)) - if offset == 0 { - copy(ends, p.ends) - } else { - for i, end := range p.ends { - ends[i] = end + offset - } - } - g.flatCoords = append(g.flatCoords, p.flatCoords...) - g.endss = append(g.endss, ends) - return nil -} - -// SetCoords sets the coordinates. -func (g *MultiPolygon) SetCoords(coords [][][]Coord) (*MultiPolygon, error) { - if err := g.setCoords(coords); err != nil { - return nil, err - } - return g, nil -} - -// SetSRID sets the SRID of g. -func (g *MultiPolygon) SetSRID(srid int) *MultiPolygon { - g.srid = srid - return g -} - -// Swap swaps the values of g and g2. -func (g *MultiPolygon) Swap(g2 *MultiPolygon) { - *g, *g2 = *g2, *g -} diff --git a/vendor/github.com/twpayne/go-geom/point.go b/vendor/github.com/twpayne/go-geom/point.go deleted file mode 100644 index 3726aa4..0000000 --- a/vendor/github.com/twpayne/go-geom/point.go +++ /dev/null @@ -1,93 +0,0 @@ -package geom - -// A Point represents a single point. -type Point struct { - geom0 -} - -// NewPoint allocates a new Point with layout l and all values zero. -func NewPoint(l Layout) *Point { - return NewPointFlat(l, make([]float64, l.Stride())) -} - -// NewPointFlat allocates a new Point with layout l and flat coordinates flatCoords. -func NewPointFlat(l Layout, flatCoords []float64) *Point { - g := new(Point) - g.layout = l - g.stride = l.Stride() - g.flatCoords = flatCoords - return g -} - -// Area returns g's area, i.e. zero. -func (g *Point) Area() float64 { - return 0 -} - -// Clone returns a copy of g that does not alias g. -func (g *Point) Clone() *Point { - return deriveClonePoint(g) -} - -// Empty returns false. -func (g *Point) Empty() bool { - return false -} - -// Length returns the length of g, i.e. zero. -func (g *Point) Length() float64 { - return 0 -} - -// MustSetCoords is like SetCoords but panics on any error. -func (g *Point) MustSetCoords(coords Coord) *Point { - Must(g.SetCoords(coords)) - return g -} - -// SetCoords sets the coordinates of g. -func (g *Point) SetCoords(coords Coord) (*Point, error) { - if err := g.setCoords(coords); err != nil { - return nil, err - } - return g, nil -} - -// SetSRID sets the SRID of g. -func (g *Point) SetSRID(srid int) *Point { - g.srid = srid - return g -} - -// Swap swaps the values of g and g2. -func (g *Point) Swap(g2 *Point) { - *g, *g2 = *g2, *g -} - -// X returns g's X-coordinate. -func (g *Point) X() float64 { - return g.flatCoords[0] -} - -// Y returns g's Y-coordinate. -func (g *Point) Y() float64 { - return g.flatCoords[1] -} - -// Z returns g's Z-coordinate, or zero if g has no Z-coordinate. -func (g *Point) Z() float64 { - zIndex := g.layout.ZIndex() - if zIndex == -1 { - return 0 - } - return g.flatCoords[zIndex] -} - -// M returns g's M-coordinate, or zero if g has no M-coordinate. -func (g *Point) M() float64 { - mIndex := g.layout.MIndex() - if mIndex == -1 { - return 0 - } - return g.flatCoords[mIndex] -} diff --git a/vendor/github.com/twpayne/go-geom/polygon.go b/vendor/github.com/twpayne/go-geom/polygon.go deleted file mode 100644 index eb77c7b..0000000 --- a/vendor/github.com/twpayne/go-geom/polygon.go +++ /dev/null @@ -1,92 +0,0 @@ -package geom - -// A Polygon represents a polygon as a collection of LinearRings. The first -// LinearRing is the outer boundary. Subsequent LinearRings are inner -// boundaries (holes). -type Polygon struct { - geom2 -} - -// NewPolygon returns a new, empty, Polygon. -func NewPolygon(layout Layout) *Polygon { - return NewPolygonFlat(layout, nil, nil) -} - -// NewPolygonFlat returns a new Polygon with the given flat coordinates. -func NewPolygonFlat(layout Layout, flatCoords []float64, ends []int) *Polygon { - g := new(Polygon) - g.layout = layout - g.stride = layout.Stride() - g.flatCoords = flatCoords - g.ends = ends - return g -} - -// Area returns the area. -func (g *Polygon) Area() float64 { - return doubleArea2(g.flatCoords, 0, g.ends, g.stride) / 2 -} - -// Clone returns a deep copy. -func (g *Polygon) Clone() *Polygon { - return deriveClonePolygon(g) -} - -// Empty returns false. -func (g *Polygon) Empty() bool { - return false -} - -// Length returns the perimter. -func (g *Polygon) Length() float64 { - return length2(g.flatCoords, 0, g.ends, g.stride) -} - -// LinearRing returns the ith LinearRing. -func (g *Polygon) LinearRing(i int) *LinearRing { - offset := 0 - if i > 0 { - offset = g.ends[i-1] - } - return NewLinearRingFlat(g.layout, g.flatCoords[offset:g.ends[i]]) -} - -// MustSetCoords sets the coordinates and panics on any error. -func (g *Polygon) MustSetCoords(coords [][]Coord) *Polygon { - Must(g.SetCoords(coords)) - return g -} - -// NumLinearRings returns the number of LinearRings. -func (g *Polygon) NumLinearRings() int { - return len(g.ends) -} - -// Push appends a LinearRing. -func (g *Polygon) Push(lr *LinearRing) error { - if lr.layout != g.layout { - return ErrLayoutMismatch{Got: lr.layout, Want: g.layout} - } - g.flatCoords = append(g.flatCoords, lr.flatCoords...) - g.ends = append(g.ends, len(g.flatCoords)) - return nil -} - -// SetCoords sets the coordinates. -func (g *Polygon) SetCoords(coords [][]Coord) (*Polygon, error) { - if err := g.setCoords(coords); err != nil { - return nil, err - } - return g, nil -} - -// SetSRID sets the SRID of g. -func (g *Polygon) SetSRID(srid int) *Polygon { - g.srid = srid - return g -} - -// Swap swaps the values of g and g2. -func (g *Polygon) Swap(g2 *Polygon) { - *g, *g2 = *g2, *g -} diff --git a/vendor/github.com/whosonfirst/go-reader-http/.gitignore b/vendor/github.com/whosonfirst/go-reader-http/.gitignore deleted file mode 100644 index afa44cd..0000000 --- a/vendor/github.com/whosonfirst/go-reader-http/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -*~ -pkg -src -!vendor/src -bin -!bin/.gitignore -*.log -*.json -.travis.yml -*.db -testdata/*.txt \ No newline at end of file diff --git a/vendor/github.com/whosonfirst/go-reader-http/LICENSE b/vendor/github.com/whosonfirst/go-reader-http/LICENSE deleted file mode 100644 index 29b6a83..0000000 --- a/vendor/github.com/whosonfirst/go-reader-http/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2019, Aaron Straup Cope -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the {organization} nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/whosonfirst/go-reader-http/README.md b/vendor/github.com/whosonfirst/go-reader-http/README.md deleted file mode 100644 index 00f93da..0000000 --- a/vendor/github.com/whosonfirst/go-reader-http/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# go-reader-http - -HTTP and HTTPS support for the go-reader Reader interface. - -_This is work in progress and documentation will follow._ - -## See also - -* https://github.com/whosonfirst/go-reader diff --git a/vendor/github.com/whosonfirst/go-reader-http/go.mod b/vendor/github.com/whosonfirst/go-reader-http/go.mod deleted file mode 100644 index d6297f9..0000000 --- a/vendor/github.com/whosonfirst/go-reader-http/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/whosonfirst/go-reader-http - -go 1.12 - -require github.com/whosonfirst/go-reader v0.1.1 diff --git a/vendor/github.com/whosonfirst/go-reader-http/go.sum b/vendor/github.com/whosonfirst/go-reader-http/go.sum deleted file mode 100644 index 53ed5ff..0000000 --- a/vendor/github.com/whosonfirst/go-reader-http/go.sum +++ /dev/null @@ -1,189 +0,0 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= -cloud.google.com/go v0.39.0/go.mod h1:rVLT6fkc8chs9sfPtFc1SBH6em7n+ZoXaG+87tDISts= -contrib.go.opencensus.io/exporter/aws v0.0.0-20181029163544-2befc13012d0/go.mod h1:uu1P0UCM/6RbsMrgPa98ll8ZcHM858i/AD06a9aLRCA= -contrib.go.opencensus.io/exporter/ocagent v0.5.0/go.mod h1:ImxhfLRpxoYiSq891pBrLVhN+qmP8BTVvdH2YLs7Gl0= -contrib.go.opencensus.io/exporter/stackdriver v0.12.1/go.mod h1:iwB6wGarfphGGe/e5CWqyUk/cLzKnWsOKPVW3no6OTw= -contrib.go.opencensus.io/integrations/ocsql v0.1.4/go.mod h1:8DsSdjz3F+APR+0z0WkU1aRorQCFfRxvqjUUPMbF3fE= -contrib.go.opencensus.io/resource v0.1.1/go.mod h1:F361eGI91LCmW1I/Saf+rX0+OFcigGlFvXwEGEnkRLA= -github.com/Azure/azure-amqp-common-go/v2 v2.1.0/go.mod h1:R8rea+gJRuJR6QxTir/XuEd+YuKoUiazDC/N96FiDEU= -github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= -github.com/Azure/azure-sdk-for-go v29.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/azure-sdk-for-go v30.1.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= -github.com/Azure/azure-service-bus-go v0.9.1/go.mod h1:yzBx6/BUGfjfeqbRZny9AQIbIe3AcV9WZbAdpkoXOa0= -github.com/Azure/azure-storage-blob-go v0.8.0/go.mod h1:lPI3aLPpuLTeUwh1sViKXFxwl2B6teiRqI0deQUvsw0= -github.com/Azure/go-autorest v12.0.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20190605020000-c4ba1fdf4d36/go.mod h1:aJ4qN3TfrelA6NZ6AXsXRfmEVaYin3EDbSPJrKS8OXo= -github.com/aaronland/go-aws-session v0.0.3/go.mod h1:nc4r+JFoGM6sop/lTspmUDcRIUW/V2NWs9Nd6jQWk90= -github.com/aaronland/go-roster v0.0.1 h1:r1l4n1HfWvEtOXZvhfXX0Won9Xf6QJsigdUdzOtuy/M= -github.com/aaronland/go-roster v0.0.1/go.mod h1:AcovpxlG1XxJxX2Fjqlm63fEIBhCjEIBV4lP87FZDmI= -github.com/aaronland/go-string v0.1.0/go.mod h1:2aMIWdTqk63jZsaLLy+p9dsB1MDRqx4sHYoLtkwyYUo= -github.com/aaronland/gocloud-blob-bucket v0.0.2/go.mod h1:4ljwXsHZzCwgs8Jp/P1brEZ09Uj1CmjBXhivUvr+tWo= -github.com/aws/aws-sdk-go v1.15.27/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0= -github.com/aws/aws-sdk-go v1.19.18/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= -github.com/aws/aws-sdk-go v1.19.45/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= -github.com/aws/aws-sdk-go v1.20.6/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= -github.com/census-instrumentation/opencensus-proto v0.2.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/devigned/tab v0.1.1/go.mod h1:XG9mPq0dFghrYvoBF3xdRrJzSTX1b7IQrvaL9mzjeJY= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dimchansky/utfbom v1.1.0/go.mod h1:rO41eb7gLfo8SF1jd9F8HplJm1Fewwi4mQvIirEdv+8= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= -github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-ini/ini v1.25.4/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= -github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= -github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= -github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= -github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= -github.com/google/go-replayers/grpcreplay v0.1.0/go.mod h1:8Ig2Idjpr6gifRd6pNVggX6TC1Zw6Jx74AKp7QNH2QE= -github.com/google/go-replayers/httpreplay v0.1.0/go.mod h1:YKZViNhiGgqdBlUbI2MwGpq4pXxNmhJLPHQ7cv2b5no= -github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/martian v2.1.1-0.20190517191504-25dcb96d9e51+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/wire v0.3.0/go.mod h1:i1DMg/Lu8Sz5yYl25iOdmc5CT5qusaa+zmRWs16741s= -github.com/googleapis/gax-go v2.0.2+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= -github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/grpc-ecosystem/grpc-gateway v1.9.2/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= -github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= -github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= -github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-ieproxy v0.0.0-20190610004146-91bb50d98149/go.mod h1:31jz6HNzdxOmlERGGEc4v/dMssOfmp2p5bT/okiKFFc= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/whosonfirst/go-reader v0.0.0-20191122213718-25d6c34f3bcc h1:iZZD21HSlqi8nOgGzGb8fXjnlEO/kdVAHkBNL/k58FA= -github.com/whosonfirst/go-reader v0.0.0-20191122213718-25d6c34f3bcc/go.mod h1:k/U2jXarXsFWC2yh63kYgKIJzTEmc60lN/ipyrdT3W4= -github.com/whosonfirst/go-reader v0.0.1 h1:8FAQgnOvvPBxb6PDuPF+DzYBNR8gl27ON3fY1zU2xY4= -github.com/whosonfirst/go-reader v0.0.1/go.mod h1:k/U2jXarXsFWC2yh63kYgKIJzTEmc60lN/ipyrdT3W4= -github.com/whosonfirst/go-reader v0.0.2 h1:Bn+dJSOuXJzV9913khoJFO2iFTlsNypMvoks9Do8O/k= -github.com/whosonfirst/go-reader v0.0.2/go.mod h1:k/U2jXarXsFWC2yh63kYgKIJzTEmc60lN/ipyrdT3W4= -github.com/whosonfirst/go-reader v0.0.3 h1:q39C4kncHIF3WIFOQB8CL+1afBJzRdSHbKqGgXmjdkc= -github.com/whosonfirst/go-reader v0.0.3/go.mod h1:TNCpgVgg71qA+jhPltXpGum8gTG5TAJYNGTMJmxFZtQ= -github.com/whosonfirst/go-reader v0.1.0 h1:HPnHLv7LwjAW/2Sjbn3H3csTAWkSSl7hcRS5EW7b27o= -github.com/whosonfirst/go-reader v0.1.0/go.mod h1:TNCpgVgg71qA+jhPltXpGum8gTG5TAJYNGTMJmxFZtQ= -github.com/whosonfirst/go-reader v0.1.1 h1:0fXoYQR/Yyh3PKk+9Huwoc6dCAt8l1tjg2dEShjqcFI= -github.com/whosonfirst/go-reader v0.1.1/go.mod h1:w0AeU+Ojyfmxb7r+rcSYyxpCxrhxlHv+D9EgEwQsqcM= -github.com/whosonfirst/go-whosonfirst-reader v0.0.0-20191122203133-047f20452865/go.mod h1:xYzBn6llLD/uS6Zhh0H4LAqddEJHXdQSUIxywTnhpOU= -github.com/whosonfirst/go-whosonfirst-sources v0.1.0/go.mod h1:EUMHyGzUmqPPxlMmOp+28BFeoBdxxE0HCKRd67lkqGM= -github.com/whosonfirst/go-whosonfirst-uri v0.1.0/go.mod h1:8eaDVcc4v+HHHEDaRbApdmhPwM4/JQllw2PktvZcPVs= -go.opencensus.io v0.15.0/go.mod h1:UffZAU+4sDEINUGP/B7UfBBkq4fqLu9zXAX7ke6CHW0= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -gocloud.dev v0.18.0/go.mod h1:lhLOb91+9tKB8RnNlsx+weJGEd0AHM94huK1bmrhPwM= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190619014844-b5b0513f8c1b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20191122200657-5d9234df094c h1:HjRaKPaiWks0f5tA6ELVF7ZfqSppfPwOEEAvsrKUTO4= -golang.org/x/oauth2 v0.0.0-20191122200657-5d9234df094c/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190620070143-6f217b454f45/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.5.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.6.0/go.mod h1:btoxGiFvQNVUZQ8W08zLtrVS08CNpINPEfxXxgJL1Q4= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190508193815-b515fa19cec8/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= -google.golang.org/genproto v0.0.0-20190620144150-6af8c5fc6601/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -pack.ag/amqp v0.11.2/go.mod h1:4/cbmt4EJXSKlG6LCfWHoqmN0uFdy5i/+YFz+fTfhV4= diff --git a/vendor/github.com/whosonfirst/go-reader-http/http.go b/vendor/github.com/whosonfirst/go-reader-http/http.go deleted file mode 100644 index 519afe0..0000000 --- a/vendor/github.com/whosonfirst/go-reader-http/http.go +++ /dev/null @@ -1,96 +0,0 @@ -package reader - -import ( - "context" - "errors" - wof_reader "github.com/whosonfirst/go-reader" - "io" - _ "log" - "net/http" - "net/url" - "path/filepath" - "time" -) - -func init() { - - ctx := context.Background() - - schemes := []string{ - "http", - "https", - } - - for _, s := range schemes { - - err := wof_reader.RegisterReader(ctx, s, initializeHTTPReader) - - if err != nil { - panic(err) - } - } -} - -func initializeHTTPReader(ctx context.Context, uri string) (wof_reader.Reader, error) { - - r := NewHTTPReader() - err := r.Open(ctx, uri) - - if err != nil { - return nil, err - } - - return r, nil -} - -type HTTPReader struct { - wof_reader.Reader - url *url.URL - throttle <-chan time.Time -} - -func NewHTTPReader() wof_reader.Reader { - - rate := time.Second / 3 - throttle := time.Tick(rate) - - r := HTTPReader{ - throttle: throttle, - } - - return &r -} - -func (r *HTTPReader) Open(ctx context.Context, uri string) error { - - u, err := url.Parse(uri) - - if err != nil { - return err - } - - r.url = u - return nil -} - -func (r *HTTPReader) Read(ctx context.Context, uri string) (io.ReadCloser, error) { - - <-r.throttle - - u, _ := url.Parse(r.url.String()) - u.Path = filepath.Join(u.Path, uri) - - url := u.String() - - rsp, err := http.Get(url) - - if err != nil { - return nil, err - } - - if rsp.StatusCode != 200 { - return nil, errors.New(rsp.Status) - } - - return rsp.Body, nil -} diff --git a/vendor/github.com/whosonfirst/go-reader/.gitignore b/vendor/github.com/whosonfirst/go-reader/.gitignore deleted file mode 100644 index afa44cd..0000000 --- a/vendor/github.com/whosonfirst/go-reader/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -*~ -pkg -src -!vendor/src -bin -!bin/.gitignore -*.log -*.json -.travis.yml -*.db -testdata/*.txt \ No newline at end of file diff --git a/vendor/github.com/whosonfirst/go-reader/LICENSE b/vendor/github.com/whosonfirst/go-reader/LICENSE deleted file mode 100644 index 29b6a83..0000000 --- a/vendor/github.com/whosonfirst/go-reader/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2019, Aaron Straup Cope -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the {organization} nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/whosonfirst/go-reader/Makefile b/vendor/github.com/whosonfirst/go-reader/Makefile deleted file mode 100644 index e69de29..0000000 diff --git a/vendor/github.com/whosonfirst/go-reader/README.md b/vendor/github.com/whosonfirst/go-reader/README.md deleted file mode 100644 index e2b0ec1..0000000 --- a/vendor/github.com/whosonfirst/go-reader/README.md +++ /dev/null @@ -1,319 +0,0 @@ -# go-reader - -There are many interfaces for reading files. This one is ours. It returns `io.ReadCloser` instances. - -_This package supersedes the [go-whosonfirst-readwrite](https://github.com/whosonfirst/go-whosonfirst-readwrite) package._ - -## Important - -There is a known bug where creating two different `Reader` instances with the same scheme but different details does not work as expected. - -## Example - -Readers are instantiated with the `reader.NewReader` method which takes as its arguments a `context.Context` instance and a URI string. The URI's scheme represents the type of reader it implements and the remaining (URI) properties are used by that reader type to instantiate itself. - -For example to read files from a directory on the local filesystem you would write: - -``` -package main - -import ( - "context" - "github.com/whosonfirst/go-reader" - "io" - "os" -) - -func main() { - ctx := context.Background() - r, _ := reader.NewReader(ctx, "fs:///usr/local/data") - fh, _ := r.Read(ctx, "example.txt") - defer fh.Close() - io.Copy(os.Stdout, fh) -} -``` - -Note the use of the `fs://` scheme rather than the more conventional `file://`. This is deliberate so as not to overlap with the [Go Cloud](https://gocloud.dev/howto/blob/) `Blob` package's file handler. - -There is also a handy "null" reader in case you need a "pretend" reader that doesn't actually do anything: - -``` -package main - -import ( - "context" - "github.com/whosonfirst/go-reader" - "io" - "os" -) - -func main() { - ctx := context.Background() - r, _ := reader.NewReader(ctx, "null://") - fh, _ := r.Read(ctx, "example.txt") - defer fh.Close() - io.Copy(os.Stdout, fh) -} -``` - -## Interfaces - -### reader.Reader - -``` -type Reader interface { - Open(context.Context, string) error - Read(context.Context, string) (io.ReadCloser, error) - URI(string) string -} -``` - -Should this interface have a `Close()` method? Maybe. We'll see. - -## Custom readers - -Custom readers need to: - -1. Implement the interface above. -2. Announce their availability using the `go-reader.RegisterReader` method on initialization, passing in an initialization function implementing the `go-reader.ReaderInitializationFunc` interface. - -For example, this is how the [go-reader-http](https://github.com/whosonfirst/go-reader-http) reader is implemented: - -``` -package reader - -import ( - "context" - "errors" - wof_reader "github.com/whosonfirst/go-reader" - "io" - "net/http" - "net/url" - "path/filepath" - "time" -) - -func init() { - - ctx := context.Background() - - schemes := []string{ - "http", - "https", - } - - for _, s := range schemes { - - err := wof_reader.RegisterReader(ctx, s, initializeHTTPReader) - - if err != nil { - panic(err) - } - } -} - -func initializeHTTPReader(ctx context.Context, uri string) (wof_reader.Reader, error) { - - r := NewHTTPReader() - err := r.Open(ctx, uri) - - if err != nil { - return nil, err - } - - return r, nil -} - -type HTTPReader struct { - wof_reader.Reader - url *url.URL - throttle <-chan time.Time -} - -func NewHTTPReader() wof_reader.Reader { - - rate := time.Second / 3 - throttle := time.Tick(rate) - - r := HTTPReader{ - throttle: throttle, - } - - return &r -} - -func (r *HTTPReader) Open(ctx context.Context, uri string) error { - - u, err := url.Parse(uri) - - if err != nil { - return err - } - - r.url = u - return nil -} - -func (r *HTTPReader) Read(ctx context.Context, uri string) (io.ReadCloser, error) { - - <-r.throttle - - u, _ := url.Parse(r.url.String()) - u.Path = filepath.Join(u.Path, uri) - - url := u.String() - - rsp, err := http.Get(url) - - if err != nil { - return nil, err - } - - if rsp.StatusCode != 200 { - return nil, errors.New(rsp.Status) - } - - return rsp.Body, nil -} -``` - -And then to use it you would do this: - -``` -package main - -import ( - "context" - "github.com/whosonfirst/go-reader" - _ "github.com/whosonfirst/go-reader-http" - "io" - "os" -) - -func main() { - ctx := context.Background() - r, _ := reader.NewReader(ctx, "https://data.whosonfirst.org") - fh, _ := r.Read(ctx, "101/736/545/101736545.geojson") - defer fh.Close() - io.Copy(os.Stdout, fh) -} -``` - -## Available readers - -### "blob" - -Read files from any registered [Go Cloud](https://gocloud.dev/howto/blob/) `Blob` source. For example: - -``` -import ( - "context" - "github.com/whosonfirst/go-reader" - _ "github.com/whosonfirst/go-reader-blob" - _ "gocloud.dev/blob/s3blob" -) - -func main() { - ctx := context.Background() - r, _ := reader.NewReader(ctx, "s3://whosonfirst-data?region=us-west-1") -} -``` - -* https://github.com/whosonfirst/go-reader-blob - -### github:// - -Read files from a GitHub repository. - -``` -import ( - "context" - "github.com/whosonfirst/go-reader" - _ "github.com/whosonfirst/go-reader-github" -) - -func main() { - ctx := context.Background() - r, _ := reader.NewReader(ctx, "github://{GITHUB_OWNER}/{GITHUB_REPO}") - - // to specify a specific branch you would do this: - // r, _ := reader.NewReader(ctx, "github://{GITHUB_OWNER}/{GITHUB_REPO}/{GITHUB_BRANCH}") -} -``` - -* https://github.com/whosonfirst/go-reader-github - -### githubapi:// - -Read files from a GitHub repository using the GitHub API. - -``` -import ( - "context" - "github.com/whosonfirst/go-reader" - _ "github.com/whosonfirst/go-reader-github" -) - -func main() { - ctx := context.Background() - r, _ := reader.NewReader(ctx, "githubapi://{GITHUB_OWNER}/{GITHUB_REPO}?access_token={GITHUBAPI_ACCESS_TOKEN}") - - // to specify a specific branch you would do this: - // r, _ := reader.NewReader(ctx, "githubapi://{GITHUB_OWNER}/{GITHUB_REPO}/{GITHUB_BRANCH}?access_token={GITHUBAPI_ACCESS_TOKEN}") -} -``` - -* https://github.com/whosonfirst/go-reader-github - -### http:// and https:// - -Read files from an HTTP(S) endpoint. - -``` -import ( - "context" - "github.com/whosonfirst/go-reader" - _ "github.com/whosonfirst/go-reader-http" -) - -func main() { - ctx := context.Background() - r, _ := reader.NewReader(ctx, "https://{HTTP_HOST_AND_PATH}") -} -``` - -* https://github.com/whosonfirst/go-reader-http - -### fs:// - -Read files from a local filesystem. - -``` -import ( - "context" - "github.com/whosonfirst/go-reader" -) - -func main() { - ctx := context.Background() - r, _ := reader.NewReader(ctx, "fs://{PATH_TO_DIRECTORY}") -} -``` - -* https://github.com/whosonfirst/go-reader - -### null:// - -Pretend to read files. - -``` -import ( - "context" - "github.com/whosonfirst/go-reader" -) - -func main() { - ctx := context.Background() - r, _ := reader.NewReader(ctx, "null://") -} -``` \ No newline at end of file diff --git a/vendor/github.com/whosonfirst/go-reader/fs.go b/vendor/github.com/whosonfirst/go-reader/fs.go deleted file mode 100644 index 88b0136..0000000 --- a/vendor/github.com/whosonfirst/go-reader/fs.go +++ /dev/null @@ -1,82 +0,0 @@ -package reader - -import ( - "context" - "errors" - "io" - "net/url" - "os" - "path/filepath" -) - -func init() { - - ctx := context.Background() - err := RegisterReader(ctx, "fs", initializeFSReader) - - if err != nil { - panic(err) - } -} - -func initializeFSReader(ctx context.Context, uri string) (Reader, error) { - - r := NewFSReader() - err := r.Open(ctx, uri) - - if err != nil { - return nil, err - } - - return r, nil -} - -type FSReader struct { - Reader - root string -} - -func NewFSReader() Reader { - r := FSReader{} - return &r -} - -func (r *FSReader) Open(ctx context.Context, uri string) error { - - u, err := url.Parse(uri) - - if err != nil { - return err - } - - root := u.Path - info, err := os.Stat(root) - - if err != nil { - return err - } - - if !info.IsDir() { - return errors.New("root is not a directory") - } - - r.root = root - return nil -} - -func (r *FSReader) Read(ctx context.Context, path string) (io.ReadCloser, error) { - - abs_path := r.URI(path) - - _, err := os.Stat(abs_path) - - if err != nil { - return nil, err - } - - return os.Open(abs_path) -} - -func (r *FSReader) URI(path string) string { - return filepath.Join(r.root, path) -} diff --git a/vendor/github.com/whosonfirst/go-reader/go.mod b/vendor/github.com/whosonfirst/go-reader/go.mod deleted file mode 100644 index b144d26..0000000 --- a/vendor/github.com/whosonfirst/go-reader/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module github.com/whosonfirst/go-reader - -go 1.12 - -require github.com/aaronland/go-roster v0.0.1 diff --git a/vendor/github.com/whosonfirst/go-reader/go.sum b/vendor/github.com/whosonfirst/go-reader/go.sum deleted file mode 100644 index 2a8d8fe..0000000 --- a/vendor/github.com/whosonfirst/go-reader/go.sum +++ /dev/null @@ -1,28 +0,0 @@ -github.com/aaronland/go-roster v0.0.1 h1:r1l4n1HfWvEtOXZvhfXX0Won9Xf6QJsigdUdzOtuy/M= -github.com/aaronland/go-roster v0.0.1/go.mod h1:AcovpxlG1XxJxX2Fjqlm63fEIBhCjEIBV4lP87FZDmI= -github.com/facebookgo/atomicfile v0.0.0-20151019000000-2de1f203e7d5e386a6833233882782932729f27e h1:bYAD+4OJX4+LUrmLhpNFiicL4B0mnswQe5QaI6rxJ4A= -github.com/facebookgo/atomicfile v0.0.0-20151019000000-2de1f203e7d5e386a6833233882782932729f27e/go.mod h1:JpoxHjuQauoxiFMl1ie8Xc/7TfLuMZ5eOCONd1sUBHg= -github.com/go-ini/ini v1.42.0 h1:TWr1wGj35+UiWHlBA8er89seFXxzwFn11spilrrj+38= -github.com/go-ini/ini v1.42.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= -github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/whosonfirst/go-whosonfirst-cache v0.1.0 h1:ryWTsHj7gAEjwHC/WjsjROpFflsz3SCa7W9Qnk4EU7k= -github.com/whosonfirst/go-whosonfirst-cache v0.1.0/go.mod h1:P5Tx34j2M50qX/kTfXY516apwGzJGkFSBYQI7TGArKw= -github.com/whosonfirst/go-whosonfirst-cli v0.1.0 h1:Wwj9z0R/ryHmPmpVm5jCbXdG4agJzKMWXDtPVReN/KA= -github.com/whosonfirst/go-whosonfirst-cli v0.1.0/go.mod h1:Edy+amD+fMq1QS1yxB3u8maA8I93q/LG7JRNh+fsdfc= -github.com/whosonfirst/go-whosonfirst-reader v0.0.0-20191122203133-047f20452865 h1:1GYjmjunRhDm1E4/aM/AIhjBij8C9kMqufjS1G2P0fs= -github.com/whosonfirst/go-whosonfirst-reader v0.0.0-20191122203133-047f20452865/go.mod h1:xYzBn6llLD/uS6Zhh0H4LAqddEJHXdQSUIxywTnhpOU= -github.com/whosonfirst/go-whosonfirst-sources v0.1.0 h1:JuKLa6KWke22jBfJ1pM9WQHoz1/3pbDv2C+aR+THPPQ= -github.com/whosonfirst/go-whosonfirst-sources v0.1.0/go.mod h1:EUMHyGzUmqPPxlMmOp+28BFeoBdxxE0HCKRd67lkqGM= -github.com/whosonfirst/go-whosonfirst-uri v0.1.0 h1:JMlpam0x1hVrFBMTAPY3edIHz7azfMK8lLI2kM9BgbI= -github.com/whosonfirst/go-whosonfirst-uri v0.1.0/go.mod h1:8eaDVcc4v+HHHEDaRbApdmhPwM4/JQllw2PktvZcPVs= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= diff --git a/vendor/github.com/whosonfirst/go-reader/null.go b/vendor/github.com/whosonfirst/go-reader/null.go deleted file mode 100644 index 02b1661..0000000 --- a/vendor/github.com/whosonfirst/go-reader/null.go +++ /dev/null @@ -1,52 +0,0 @@ -package reader - -import ( - "bytes" - "context" - "io" - "io/ioutil" -) - -func init() { - - ctx := context.Background() - err := RegisterReader(ctx, "null", initializeNullReader) - - if err != nil { - panic(err) - } -} - -func initializeNullReader(ctx context.Context, uri string) (Reader, error) { - - r := NewNullReader() - err := r.Open(ctx, uri) - - if err != nil { - return nil, err - } - - return r, nil -} - -type NullReader struct { - Reader -} - -func NewNullReader() Reader { - r := NullReader{} - return &r -} - -func (r *NullReader) Open(ctx context.Context, uri string) error { - return nil -} - -func (r *NullReader) Read(ctx context.Context, uri string) (io.ReadCloser, error) { - br := bytes.NewReader([]byte(uri)) - return ioutil.NopCloser(br), nil -} - -func (r *NullReader) URI(uri string) string { - return uri -} diff --git a/vendor/github.com/whosonfirst/go-reader/reader.go b/vendor/github.com/whosonfirst/go-reader/reader.go deleted file mode 100644 index 48a98ab..0000000 --- a/vendor/github.com/whosonfirst/go-reader/reader.go +++ /dev/null @@ -1,96 +0,0 @@ -package reader - -import ( - "context" - "github.com/aaronland/go-roster" - "io" - "net/url" -) - -var reader_roster roster.Roster - -type ReaderInitializationFunc func(ctx context.Context, uri string) (Reader, error) - -type Reader interface { - Open(context.Context, string) error - Read(context.Context, string) (io.ReadCloser, error) - URI(string) string -} - -func NewService(ctx context.Context, uri string) (Reader, error) { - - err := ensureReaderRoster() - - if err != nil { - return nil, err - } - - parsed, err := url.Parse(uri) - - if err != nil { - return nil, err - } - - scheme := parsed.Scheme - - i, err := reader_roster.Driver(ctx, scheme) - - if err != nil { - return nil, err - } - - init_func := i.(ReaderInitializationFunc) - return init_func(ctx, uri) -} - -func RegisterReader(ctx context.Context, scheme string, init_func ReaderInitializationFunc) error { - - err := ensureReaderRoster() - - if err != nil { - return err - } - - return reader_roster.Register(ctx, scheme, init_func) -} - -func ensureReaderRoster() error { - - if reader_roster == nil { - - r, err := roster.NewDefaultRoster() - - if err != nil { - return err - } - - reader_roster = r - } - - return nil -} - -func NewReader(ctx context.Context, uri string) (Reader, error) { - - u, err := url.Parse(uri) - - if err != nil { - return nil, err - } - - scheme := u.Scheme - - i, err := reader_roster.Driver(ctx, scheme) - - if err != nil { - return nil, err - } - - init_func := i.(ReaderInitializationFunc) - return init_func(ctx, uri) -} - -func Readers() []string { - ctx := context.Background() - return reader_roster.Drivers(ctx) -} diff --git a/vendor/github.com/whosonfirst/go-rfc-5646/.gitignore b/vendor/github.com/whosonfirst/go-rfc-5646/.gitignore deleted file mode 100644 index f5cccdd..0000000 --- a/vendor/github.com/whosonfirst/go-rfc-5646/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -*~ -pkg -src -!vendor/src -bin -!bin/.gitignore -*.log -*.json -.travis.yml -*.db \ No newline at end of file diff --git a/vendor/github.com/whosonfirst/go-rfc-5646/5646.go b/vendor/github.com/whosonfirst/go-rfc-5646/5646.go deleted file mode 100644 index fe0c700..0000000 --- a/vendor/github.com/whosonfirst/go-rfc-5646/5646.go +++ /dev/null @@ -1,101 +0,0 @@ -package rfc5646 - -import ( - "regexp" -) - -var RE_LANGUAGETAG *regexp.Regexp - -func init() { - - RE_LANGUAGETAG = regexp.MustCompile(`^((?P(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?P([A-Za-z]{2,3}(-(?P[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?P