diff --git a/database.go b/database.go index ab0667e..6662373 100644 --- a/database.go +++ b/database.go @@ -17,7 +17,6 @@ import ( "github.com/whosonfirst/go-whosonfirst-spatial" "github.com/whosonfirst/go-whosonfirst-spatial/database" "github.com/whosonfirst/go-whosonfirst-spatial/filter" - "github.com/whosonfirst/go-whosonfirst-spatial/timer" "github.com/whosonfirst/go-whosonfirst-spr/v2" "github.com/whosonfirst/go-whosonfirst-uri" "io" @@ -44,7 +43,6 @@ type RTreeCache struct { type RTreeSpatialDatabase struct { database.SpatialDatabase Logger *log.Logger - Timer *timer.Timer index_alt_files bool rtree *rtreego.Rtree gocache *gocache.Cache @@ -140,11 +138,8 @@ func NewRTreeSpatialDatabase(ctx context.Context, uri string) (database.SpatialD mu := new(sync.RWMutex) - t := timer.NewTimer() - db := &RTreeSpatialDatabase{ Logger: logger, - Timer: t, rtree: rtree, index_alt_files: index_alt_files, gocache: gc, @@ -462,9 +457,6 @@ func (r *RTreeSpatialDatabase) getIntersectsByCoord(coord *orb.Point) ([]rtreego func (r *RTreeSpatialDatabase) getIntersectsByRect(rect *rtreego.Rect) ([]rtreego.Spatial, error) { - // to do: timings that don't slow everything down the way - // go-whosonfirst-timer does now (20170915/thisisaaronland) - results := r.rtree.SearchIntersect(rect) return results, nil } @@ -486,12 +478,6 @@ func (r *RTreeSpatialDatabase) inflateResultsWithChannels(ctx context.Context, r sp_id := sp.Id feature_id := sp.FeatureId - t1 := time.Now() - - defer func() { - r.Timer.Add(ctx, sp_id, "time to inflate", time.Since(t1)) - }() - defer wg.Done() select { @@ -513,12 +499,8 @@ func (r *RTreeSpatialDatabase) inflateResultsWithChannels(ctx context.Context, r seen[feature_id] = true mu.Unlock() - t2 := time.Now() - cache_item, err := r.retrieveCache(ctx, sp) - r.Timer.Add(ctx, sp_id, "time to retrieve cache", time.Since(t2)) - if err != nil { r.Logger.Printf("Failed to retrieve cache for %s, %v", sp_id, err) return @@ -526,8 +508,6 @@ func (r *RTreeSpatialDatabase) inflateResultsWithChannels(ctx context.Context, r s := cache_item.SPR - t3 := time.Now() - for _, f := range filters { err = filter.FilterSPR(f, s) @@ -538,10 +518,6 @@ func (r *RTreeSpatialDatabase) inflateResultsWithChannels(ctx context.Context, r } } - r.Timer.Add(ctx, sp_id, "time to filter", time.Since(t3)) - - t4 := time.Now() - geom := cache_item.Geometry orb_geom := geom.Geometry() @@ -558,8 +534,6 @@ func (r *RTreeSpatialDatabase) inflateResultsWithChannels(ctx context.Context, r r.Logger.Printf("Geometry has unsupported geometry type '%s'", geom.Type) } - r.Timer.Add(ctx, sp_id, "time to test geometry", time.Since(t4)) - if !contains { // r.Logger.Debug("SKIP %s because does not contain coord (%v)", sp_id, c) return diff --git a/go.mod b/go.mod index 26000a2..36461ed 100644 --- a/go.mod +++ b/go.mod @@ -8,29 +8,31 @@ require ( github.com/paulmach/orb v0.7.1 github.com/sfomuseum/go-flags v0.10.0 github.com/whosonfirst/go-ioutil v1.0.2 - github.com/whosonfirst/go-whosonfirst-feature v0.0.24 - github.com/whosonfirst/go-whosonfirst-spatial v0.4.0 - github.com/whosonfirst/go-whosonfirst-spr/v2 v2.2.1 + github.com/whosonfirst/go-whosonfirst-feature v0.0.25 + github.com/whosonfirst/go-whosonfirst-spatial v0.5.4 + github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.3 github.com/whosonfirst/go-whosonfirst-uri v1.2.0 ) require ( - github.com/aaronland/go-json-query v0.1.2 // indirect + github.com/aaronland/go-json-query v0.1.3 // indirect github.com/aaronland/go-roster v1.0.0 // indirect github.com/g8rswimmer/error-chain v1.0.0 // indirect + github.com/hashicorp/errwrap v1.0.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/natefinch/atomic v1.0.1 // indirect github.com/sfomuseum/go-edtf v1.1.1 // indirect - github.com/tidwall/gjson v1.14.3 // indirect + github.com/tidwall/gjson v1.14.4 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect github.com/tidwall/sjson v1.2.5 // indirect - github.com/whosonfirst/go-reader v1.0.1 // indirect + github.com/whosonfirst/go-reader v1.0.2 // indirect github.com/whosonfirst/go-sanitize v0.1.0 // indirect github.com/whosonfirst/go-whosonfirst-crawl v0.2.1 // indirect github.com/whosonfirst/go-whosonfirst-flags v0.4.4 // indirect - github.com/whosonfirst/go-whosonfirst-iterate/v2 v2.3.0 // indirect - github.com/whosonfirst/go-whosonfirst-placetypes v0.3.0 // indirect + github.com/whosonfirst/go-whosonfirst-iterate/v2 v2.3.1 // indirect + github.com/whosonfirst/go-whosonfirst-placetypes v0.4.2 // indirect github.com/whosonfirst/go-whosonfirst-sources v0.1.0 // indirect - github.com/whosonfirst/go-writer/v3 v3.0.0 // indirect + github.com/whosonfirst/go-writer/v3 v3.1.0 // indirect github.com/whosonfirst/walk v0.0.1 // indirect ) diff --git a/go.sum b/go.sum index 68742db..03165ff 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/aaronland/go-json-query v0.1.2 h1:+yJBCJk9kcRAzbErhh+zOqK3DHSs/GmuSqXcCn5yH/c= -github.com/aaronland/go-json-query v0.1.2/go.mod h1:kkCl5KrO+fVSL2M8b/i3qO5PsnCpmajGXkbJHpEQPY8= +github.com/aaronland/go-json-query v0.1.3 h1:wBqGF4d+Qy1+/YFqiFEKL7ja4iaaZi9E/CWaO3s7G4U= +github.com/aaronland/go-json-query v0.1.3/go.mod h1:+T7tN35K0RtLt92MlNM+N2sr6pxsQMJc6Fd4PsKaVtw= github.com/aaronland/go-roster v1.0.0 h1:FRDGrTqsYySKjWnAhbBGXyeGlI/o5/t9FZYCbUmyQtI= github.com/aaronland/go-roster v1.0.0/go.mod h1:KIsYZgrJlAsyb9LsXSCvlqvbcCBVjCSqcQiZx42i9ro= github.com/dhconnelly/rtreego v1.1.0 h1:ejMaqN03N1s6Bdg6peGkNgBnYYSBHzcK8yhSPCB+rHE= @@ -10,31 +10,29 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v0.0.0-20171204182908-b7773ae21874/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/natefinch/atomic v1.0.1 h1:ZPYKxkqQOx3KZ+RsbnP/YsgvxWQPGxjC0oBt2AhwV0A= github.com/natefinch/atomic v1.0.1/go.mod h1:N/D/ELrljoqDyT3rZrsUmtsuzvHkeB/wWjHV22AZRbM= 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/paulmach/orb v0.6.0/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A= github.com/paulmach/orb v0.7.1 h1:Zha++Z5OX/l168sqHK3k4z18LDvr+YAO/VjK0ReQ9rU= github.com/paulmach/orb v0.7.1/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A= github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/sfomuseum/go-edtf v0.2.3/go.mod h1:1rP0EJZ/84j3HO80vGcnG2T9MFBDAFyTNtjrr8cv3T4= -github.com/sfomuseum/go-edtf v0.3.1/go.mod h1:1rP0EJZ/84j3HO80vGcnG2T9MFBDAFyTNtjrr8cv3T4= -github.com/sfomuseum/go-edtf v1.0.0/go.mod h1:1rP0EJZ/84j3HO80vGcnG2T9MFBDAFyTNtjrr8cv3T4= github.com/sfomuseum/go-edtf v1.1.1 h1:R5gElndHGDaK/rGSh2X+ulaLtlcHCdQA1cTzB8e9wv8= github.com/sfomuseum/go-edtf v1.1.1/go.mod h1:1rP0EJZ/84j3HO80vGcnG2T9MFBDAFyTNtjrr8cv3T4= github.com/sfomuseum/go-flags v0.7.0/go.mod h1:ML3DTNbF9xnjExSdS/9FtVLjIUhRU5gm/ehzISv+t2w= github.com/sfomuseum/go-flags v0.10.0 h1:1OC1ACxpWMsl3XQ9OeNVMQj7Zi2CzufP3Rym3mPI8HU= github.com/sfomuseum/go-flags v0.10.0/go.mod h1:VXOnnX1/yxQpX2yiwHaBV6aCmhtszQOL5bL1/nNo3co= -github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= -github.com/tidwall/gjson v1.14.3 h1:9jvXn7olKEHU1S9vwoMGliaT8jq1vJ7IH/n9zD9Dnlw= -github.com/tidwall/gjson v1.14.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= +github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= @@ -43,33 +41,31 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= github.com/whosonfirst/go-ioutil v1.0.2 h1:+GJPfa42OFn5A+5yJSc5jQTQIkNV3/MhYyg4pavdrC8= github.com/whosonfirst/go-ioutil v1.0.2/go.mod h1:2dS1vWdAIkiHDvDF8fYyjv6k2NISmwaIjJJeEDBEdvg= -github.com/whosonfirst/go-reader v1.0.1 h1:mvEqObVuzJyZkI37SDmuvCpTJ2iEG5GUgD2Z3mT2e7s= -github.com/whosonfirst/go-reader v1.0.1/go.mod h1:3RXON51sbyPw8Ca7sxxwOItVfx8SM+KFPR+l2azGxJA= +github.com/whosonfirst/go-reader v1.0.2 h1:eccnKKSMGR+X1SJyHUZN0/7qE7VbFQULqSVQU0Su3xs= +github.com/whosonfirst/go-reader v1.0.2/go.mod h1:2w9l/QusYZSiGuEof3RwCHUFnM492SSOF2H7UxS4YIE= github.com/whosonfirst/go-sanitize v0.1.0 h1:ygSqCnakwdzH/m8UEa15zXGDsoo5/JJeRkgmAjXZrBU= github.com/whosonfirst/go-sanitize v0.1.0/go.mod h1:p/emgbafMM0p5iVAz2XWwecYPl06Tw4Jos9rhTKIrt8= github.com/whosonfirst/go-whosonfirst-crawl v0.2.1 h1:nNG7r7/4MaII/NM8Df2oqgfgVNBDoIKlseleoX1vw1Q= github.com/whosonfirst/go-whosonfirst-crawl v0.2.1/go.mod h1:MTD1TCgAkXlAtysPU98ylrz9Y5+ZCfRrsrBnRyiH/t8= -github.com/whosonfirst/go-whosonfirst-feature v0.0.23/go.mod h1:3cvRigFFG2a99M64lZzfy5amHacWu8Os5fXZdGjPnLM= -github.com/whosonfirst/go-whosonfirst-feature v0.0.24 h1:YR3Qm0oFDc9FM4z6VXsTZ4tSBRdi/hKKQUOj9fYy/Yw= -github.com/whosonfirst/go-whosonfirst-feature v0.0.24/go.mod h1:bdRPXMN+i82aVJSVMEaO306wDITCijdSIcmgUbSp04E= -github.com/whosonfirst/go-whosonfirst-flags v0.4.3/go.mod h1:pL17Ryo60FH8RYaQRgfu5XnxhrNRK3x+rn03TYD6Gc8= +github.com/whosonfirst/go-whosonfirst-feature v0.0.25 h1:6s2to+aWB9Fo+IcwSvsB2UiuymJPKSe8g0TwuRasLhE= +github.com/whosonfirst/go-whosonfirst-feature v0.0.25/go.mod h1:JTauqAjTuZDfOTHxv5hFUzknF0NGgxvHTT5maTej9Co= github.com/whosonfirst/go-whosonfirst-flags v0.4.4 h1:pwUnE8btx4Po6N5+uq0IrKVF0WraY5YW3tc3saIDg3A= github.com/whosonfirst/go-whosonfirst-flags v0.4.4/go.mod h1:C9X7vQvNR/u55AfOHYUT8o7dRACWV++ZV4B0kylnIaY= -github.com/whosonfirst/go-whosonfirst-iterate/v2 v2.3.0 h1:Fo1njhYHl+kEk2ZP4D1L3vIlKikT/rJ3fIXnAOZodlo= -github.com/whosonfirst/go-whosonfirst-iterate/v2 v2.3.0/go.mod h1:aWeWB3DYX7bVtnNNRjCpMNZSsRgohX+FM7ukQ0cXXTY= -github.com/whosonfirst/go-whosonfirst-placetypes v0.3.0 h1:68kuizK8FXjfEIOKlqWemhs7gyMBIgpLJDbCZF8+8Ok= +github.com/whosonfirst/go-whosonfirst-iterate/v2 v2.3.1 h1:CSada4je5cY3ZdTNKhYK2khy9HpeoxLVDo2cxSoUw7k= +github.com/whosonfirst/go-whosonfirst-iterate/v2 v2.3.1/go.mod h1:sAVuLSXDCyU1Yb474H0vXzBxY4Xooeza86CfjWUUCnM= github.com/whosonfirst/go-whosonfirst-placetypes v0.3.0/go.mod h1:ez0VFkGFbgT2/z2oi3PIuW6FewsZ2+5glyfDD79XEHk= +github.com/whosonfirst/go-whosonfirst-placetypes v0.4.2 h1:Sye3ySdkTy5+PPdSLCaZO6/Pcfqb0AnMDU40c/yYZpQ= +github.com/whosonfirst/go-whosonfirst-placetypes v0.4.2/go.mod h1:HjxisIp+iZOXoThM9XyvC+GCmnupynE73GD3JxhH3fY= 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-spatial v0.4.0 h1:62ZIglrseUouqCnaqqichStGxzvLiUgAKmg6uNtvs7E= -github.com/whosonfirst/go-whosonfirst-spatial v0.4.0/go.mod h1:QB/cWzEWTBFg5gMOvxBU6aiH3T9R4fqZRgPn3lpdD/0= -github.com/whosonfirst/go-whosonfirst-spr/v2 v2.2.1 h1:WRL/a9KPyA+MC6/ChIWlRqa/1BtV94Ak9Fh4cZB0yjs= -github.com/whosonfirst/go-whosonfirst-spr/v2 v2.2.1/go.mod h1:3P6fiSVGtIbM3UcyaVMs4i1N6Hi88GmTsdouuXzlr78= -github.com/whosonfirst/go-whosonfirst-uri v1.0.1/go.mod h1:8eaDVcc4v+HHHEDaRbApdmhPwM4/JQllw2PktvZcPVs= +github.com/whosonfirst/go-whosonfirst-spatial v0.5.4 h1:JJO2K+xLyciyWVPmpQ/VKZqXAswYm0O4yaXohFCBp/c= +github.com/whosonfirst/go-whosonfirst-spatial v0.5.4/go.mod h1:Q8SCUVV0mcGZpMB3Lq9GiBXkm6ZVS/kor4GuPQGvaCA= +github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.3 h1:dc7BdkGrSKtGyIEO8jW4h6xS0DMdKANwMHFRc1+WcnM= +github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.3/go.mod h1:3Sym68fXOfIAcdJiRkJC+8FO+JuSGZ2NuDpRFzWMDi0= github.com/whosonfirst/go-whosonfirst-uri v1.2.0 h1:lhmRsIhcpTr5HAo+kXKRGsSt76HTh3Ko/oTR2jpCm/o= github.com/whosonfirst/go-whosonfirst-uri v1.2.0/go.mod h1:CuVygTCUpMG945MMvqHyqxvc/L5YkDaMrrVpRFr7ZxY= -github.com/whosonfirst/go-writer/v3 v3.0.0 h1:EyGed1mP60LbXYGTVqQl5PAkfUkLfczGOPcC9mcHTMQ= -github.com/whosonfirst/go-writer/v3 v3.0.0/go.mod h1:TmYoKR7RvrzJaj3eOgMhgXHFE+R1yuO/4smxKHFhv14= +github.com/whosonfirst/go-writer/v3 v3.1.0 h1:lEZ6TIYvZb5NJ6e2OXYRM1j+MM2svKCSlb+6Vzbz+/M= +github.com/whosonfirst/go-writer/v3 v3.1.0/go.mod h1:TmYoKR7RvrzJaj3eOgMhgXHFE+R1yuO/4smxKHFhv14= github.com/whosonfirst/walk v0.0.1 h1:t0QrqGwOdPMSeovFZSXfiS0GIGHrRXK3Wb9z5Uhs2bg= github.com/whosonfirst/walk v0.0.1/go.mod h1:1KtP/VeooSlFOI61p+THc/C16Ra8Z5MjpjI0tsd3c1M= github.com/whosonfirst/warning v0.1.1/go.mod h1:/unEMzhB9YaMeEwTJpzLN3kM5LiSxdJhKEsf/OQhn6s= diff --git a/vendor/github.com/hashicorp/errwrap/LICENSE b/vendor/github.com/hashicorp/errwrap/LICENSE new file mode 100644 index 0000000..c33dcc7 --- /dev/null +++ b/vendor/github.com/hashicorp/errwrap/LICENSE @@ -0,0 +1,354 @@ +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 new file mode 100644 index 0000000..444df08 --- /dev/null +++ b/vendor/github.com/hashicorp/errwrap/README.md @@ -0,0 +1,89 @@ +# 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, "does not exist") { + // 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 new file mode 100644 index 0000000..a733bef --- /dev/null +++ b/vendor/github.com/hashicorp/errwrap/errwrap.go @@ -0,0 +1,169 @@ +// 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 new file mode 100644 index 0000000..82b4de9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-multierror/LICENSE @@ -0,0 +1,353 @@ +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 new file mode 100644 index 0000000..b97cd6e --- /dev/null +++ b/vendor/github.com/hashicorp/go-multierror/Makefile @@ -0,0 +1,31 @@ +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 new file mode 100644 index 0000000..71dd308 --- /dev/null +++ b/vendor/github.com/hashicorp/go-multierror/README.md @@ -0,0 +1,150 @@ +# go-multierror + +[![CircleCI](https://img.shields.io/circleci/build/github/hashicorp/go-multierror/master)](https://circleci.com/gh/hashicorp/go-multierror) +[![Go Reference](https://pkg.go.dev/badge/github.com/hashicorp/go-multierror.svg)](https://pkg.go.dev/github.com/hashicorp/go-multierror) +![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/hashicorp/go-multierror) + +[circleci]: https://app.circleci.com/pipelines/github/hashicorp/go-multierror +[godocs]: https://pkg.go.dev/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` is fully compatible with the Go standard library +[errors](https://golang.org/pkg/errors/) package, including the +functions `As`, `Is`, and `Unwrap`. This provides a standardized approach +for introspecting on error values. + +## Installation and Docs + +Install using `go get github.com/hashicorp/go-multierror`. + +Full documentation is available at +https://pkg.go.dev/github.com/hashicorp/go-multierror + +### Requires go version 1.13 or newer + +`go-multierror` requires go version 1.13 or newer. Go 1.13 introduced +[error wrapping](https://golang.org/doc/go1.13#error_wrapping), which +this library takes advantage of. + +If you need to use an earlier version of go, you can use the +[v1.0.0](https://github.com/hashicorp/go-multierror/tree/v1.0.0) +tag, which doesn't rely on features in go 1.13. + +If you see compile errors that look like the below, it's likely that +you're on an older version of go: + +``` +/go/src/github.com/hashicorp/go-multierror/multierror.go:112:9: undefined: errors.As +/go/src/github.com/hashicorp/go-multierror/multierror.go:117:9: undefined: errors.Is +``` + +## 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 + } +} +``` + +You can also use the standard [`errors.Unwrap`](https://golang.org/pkg/errors/#Unwrap) +function. This will continue to unwrap into subsequent errors until none exist. + +**Extracting an error** + +The standard library [`errors.As`](https://golang.org/pkg/errors/#As) +function can be used directly with a multierror to extract a specific error: + +```go +// Assume err is a multierror value +err := somefunc() + +// We want to know if "err" has a "RichErrorType" in it and extract it. +var errRich RichErrorType +if errors.As(err, &errRich) { + // It has it, and now errRich is populated. +} +``` + +**Checking for an exact error value** + +Some errors are returned as exact errors such as the [`ErrNotExist`](https://golang.org/pkg/os/#pkg-variables) +error in the `os` package. You can check if this error is present by using +the standard [`errors.Is`](https://golang.org/pkg/errors/#Is) function. + +```go +// Assume err is a multierror value +err := somefunc() +if errors.Is(err, os.ErrNotExist) { + // err contains os.ErrNotExist +} +``` + +**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 new file mode 100644 index 0000000..3e2589b --- /dev/null +++ b/vendor/github.com/hashicorp/go-multierror/append.go @@ -0,0 +1,43 @@ +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. +// Any nil errors within errs will be ignored. If err is nil, a new +// *Error will be returned. +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 new file mode 100644 index 0000000..aab8e9a --- /dev/null +++ b/vendor/github.com/hashicorp/go-multierror/flatten.go @@ -0,0 +1,26 @@ +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 new file mode 100644 index 0000000..47f13c4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-multierror/format.go @@ -0,0 +1,27 @@ +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\t* %s\n\n", 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\t%s\n\n", + len(es), strings.Join(points, "\n\t")) +} diff --git a/vendor/github.com/hashicorp/go-multierror/group.go b/vendor/github.com/hashicorp/go-multierror/group.go new file mode 100644 index 0000000..9c29efb --- /dev/null +++ b/vendor/github.com/hashicorp/go-multierror/group.go @@ -0,0 +1,38 @@ +package multierror + +import "sync" + +// Group is a collection of goroutines which return errors that need to be +// coalesced. +type Group struct { + mutex sync.Mutex + err *Error + wg sync.WaitGroup +} + +// Go calls the given function in a new goroutine. +// +// If the function returns an error it is added to the group multierror which +// is returned by Wait. +func (g *Group) Go(f func() error) { + g.wg.Add(1) + + go func() { + defer g.wg.Done() + + if err := f(); err != nil { + g.mutex.Lock() + g.err = Append(g.err, err) + g.mutex.Unlock() + } + }() +} + +// Wait blocks until all function calls from the Go method have returned, then +// returns the multierror. +func (g *Group) Wait() *Error { + g.wg.Wait() + g.mutex.Lock() + defer g.mutex.Unlock() + return g.err +} diff --git a/vendor/github.com/hashicorp/go-multierror/multierror.go b/vendor/github.com/hashicorp/go-multierror/multierror.go new file mode 100644 index 0000000..f545743 --- /dev/null +++ b/vendor/github.com/hashicorp/go-multierror/multierror.go @@ -0,0 +1,121 @@ +package multierror + +import ( + "errors" + "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. Unlike accessing the +// Errors field directly, this function also checks if the multierror is nil to +// prevent a null-pointer panic. It satisfies the errwrap.Wrapper interface. +func (e *Error) WrappedErrors() []error { + if e == nil { + return nil + } + return e.Errors +} + +// Unwrap returns an error from Error (or nil if there are no errors). +// This error returned will further support Unwrap to get the next error, +// etc. The order will match the order of Errors in the multierror.Error +// at the time of calling. +// +// The resulting error supports errors.As/Is/Unwrap so you can continue +// to use the stdlib errors package to introspect further. +// +// This will perform a shallow copy of the errors slice. Any errors appended +// to this error after calling Unwrap will not be available until a new +// Unwrap is called on the multierror.Error. +func (e *Error) Unwrap() error { + // If we have no errors then we do nothing + if e == nil || len(e.Errors) == 0 { + return nil + } + + // If we have exactly one error, we can just return that directly. + if len(e.Errors) == 1 { + return e.Errors[0] + } + + // Shallow copy the slice + errs := make([]error, len(e.Errors)) + copy(errs, e.Errors) + return chain(errs) +} + +// chain implements the interfaces necessary for errors.Is/As/Unwrap to +// work in a deterministic way with multierror. A chain tracks a list of +// errors while accounting for the current represented error. This lets +// Is/As be meaningful. +// +// Unwrap returns the next error. In the cleanest form, Unwrap would return +// the wrapped error here but we can't do that if we want to properly +// get access to all the errors. Instead, users are recommended to use +// Is/As to get the correct error type out. +// +// Precondition: []error is non-empty (len > 0) +type chain []error + +// Error implements the error interface +func (e chain) Error() string { + return e[0].Error() +} + +// Unwrap implements errors.Unwrap by returning the next error in the +// chain or nil if there are no more errors. +func (e chain) Unwrap() error { + if len(e) == 1 { + return nil + } + + return e[1:] +} + +// As implements errors.As by attempting to map to the current value. +func (e chain) As(target interface{}) bool { + return errors.As(e[0], target) +} + +// Is implements errors.Is by comparing the current value directly. +func (e chain) Is(target error) bool { + return errors.Is(e[0], target) +} diff --git a/vendor/github.com/hashicorp/go-multierror/prefix.go b/vendor/github.com/hashicorp/go-multierror/prefix.go new file mode 100644 index 0000000..5c477ab --- /dev/null +++ b/vendor/github.com/hashicorp/go-multierror/prefix.go @@ -0,0 +1,37 @@ +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/hashicorp/go-multierror/sort.go b/vendor/github.com/hashicorp/go-multierror/sort.go new file mode 100644 index 0000000..fecb14e --- /dev/null +++ b/vendor/github.com/hashicorp/go-multierror/sort.go @@ -0,0 +1,16 @@ +package multierror + +// Len implements sort.Interface function for length +func (err Error) Len() int { + return len(err.Errors) +} + +// Swap implements sort.Interface function for swapping elements +func (err Error) Swap(i, j int) { + err.Errors[i], err.Errors[j] = err.Errors[j], err.Errors[i] +} + +// Less implements sort.Interface function for determining order +func (err Error) Less(i, j int) bool { + return err.Errors[i].Error() < err.Errors[j].Error() +} diff --git a/vendor/github.com/tidwall/gjson/README.md b/vendor/github.com/tidwall/gjson/README.md index 00b4c96..c8db11f 100644 --- a/vendor/github.com/tidwall/gjson/README.md +++ b/vendor/github.com/tidwall/gjson/README.md @@ -176,7 +176,7 @@ The `result.Int()` and `result.Uint()` calls are capable of reading all 64 bits, ```go result.Int() int64 // -9223372036854775808 to 9223372036854775807 -result.Uint() int64 // 0 to 18446744073709551615 +result.Uint() uint64 // 0 to 18446744073709551615 ``` ## Modifiers and path chaining diff --git a/vendor/github.com/tidwall/gjson/gjson.go b/vendor/github.com/tidwall/gjson/gjson.go index 330218d..53cbd23 100644 --- a/vendor/github.com/tidwall/gjson/gjson.go +++ b/vendor/github.com/tidwall/gjson/gjson.go @@ -1009,8 +1009,8 @@ func parseObjectPath(path string) (r objectPathResult) { r.piped = true } else { r.path = path[i+1:] + r.more = true } - r.more = true return } else if path[i] == '|' { r.part = string(epart) diff --git a/vendor/github.com/whosonfirst/go-reader/doc.go b/vendor/github.com/whosonfirst/go-reader/doc.go index 6ef1b89..229e60d 100644 --- a/vendor/github.com/whosonfirst/go-reader/doc.go +++ b/vendor/github.com/whosonfirst/go-reader/doc.go @@ -1,13 +1,13 @@ // Example: // -// package main +// package main // -// import ( +// import ( // "context" -// "github.com/whosonfirst/go-reader" -// "io" +// "github.com/whosonfirst/go-reader" +// "io" // "os" -// ) +// ) // // func main() { // ctx := context.Background() @@ -36,11 +36,10 @@ // // ctx := context.Background() // -// err = RegisterReader(ctx, "file", NewFileReader) +// err = RegisterReader(ctx, "file", NewFileReader) // // if err != nil { -// panic(err) -// } -// } -// +// panic(err) +// } +// } package reader diff --git a/vendor/github.com/whosonfirst/go-reader/multi.go b/vendor/github.com/whosonfirst/go-reader/multi.go index 0b09d31..8f6dc22 100644 --- a/vendor/github.com/whosonfirst/go-reader/multi.go +++ b/vendor/github.com/whosonfirst/go-reader/multi.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/hashicorp/go-multierror" "io" _ "log" "sync" @@ -28,7 +29,7 @@ func NewMultiReaderFromURIs(ctx context.Context, uris ...string) (Reader, error) r, err := NewReader(ctx, uri) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to create reader for %s, %w", uri, err) } readers = append(readers, r) @@ -80,11 +81,15 @@ func (mr *MultiReader) Read(ctx context.Context, path string) (io.ReadSeekCloser var fh io.ReadSeekCloser idx = -1 + var errors error + for i, r := range mr.readers { rsp, err := r.Read(ctx, path) - if err == nil { + if err != nil { + errors = multierror.Append(fmt.Errorf("Failed to read %s with %T, %w", path, r, err)) + } else { fh = rsp idx = i @@ -100,7 +105,7 @@ func (mr *MultiReader) Read(ctx context.Context, path string) (io.ReadSeekCloser mr.mu.Unlock() if fh == nil { - return nil, missing + return nil, errors } return fh, nil diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/Makefile b/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/Makefile index 34eae2c..406090c 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/Makefile +++ b/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/Makefile @@ -5,4 +5,4 @@ cli: go build -mod vendor -o bin/wof-valid-placetype cmd/wof-valid-placetype/main.go spec: - go run cmd/mk-spec/main.go > placetypes/spec.go + curl -o placetypes.json https://raw.githubusercontent.com/whosonfirst/whosonfirst-placetypes/master/data/placetypes-spec-latest.json diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/placetypes.go b/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/placetypes.go index 223890a..225c972 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/placetypes.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/placetypes.go @@ -1,13 +1,18 @@ package placetypes import ( + "fmt" "log" "strconv" + "strings" + "sync" ) type WOFPlacetypeName struct { + // Lang is the RFC 5646 (BCP-47) language tag for the placetype name Lang string `json:"language"` Kind string `json:"kind"` + // Name is the name of the placetype (in the language defined by `Lang`) Name string `json:"name"` } @@ -23,16 +28,42 @@ type WOFPlacetype struct { var specification *WOFPlacetypeSpecification -func init() { +var relationships *sync.Map - var err error +func init() { - specification, err = DefaultWOFPlacetypeSpecification() + s, err := DefaultWOFPlacetypeSpecification() if err != nil { - log.Fatal("Failed to parse specification", err) + log.Fatal("Failed to load default WOF specification", err) } + specification = s + + relationships = new(sync.Map) + + go func() { + + roles := []string{ + "common", + "optional", + "common_optional", + } + + count_roles := len(roles) + + for i := 0; i < count_roles; i++ { + + pt_roles := roles[0:i] + + for _, pt := range specification.catalog { + go Children(&pt) + go DescendantsForRoles(&pt, pt_roles) + go AncestorsForRoles(&pt, pt_roles) + } + } + }() + } func GetPlacetypeByName(name string) (*WOFPlacetype, error) { @@ -51,6 +82,7 @@ func AppendPlacetypeSpecification(spec *WOFPlacetypeSpecification) error { return specification.AppendPlacetypeSpecification(spec) } +// Placetypes returns all the known placetypes for the 'common', 'optional' and 'common_optional' roles. func Placetypes() ([]*WOFPlacetype, error) { roles := []string{ @@ -67,7 +99,7 @@ func PlacetypesForRoles(roles []string) ([]*WOFPlacetype, error) { pl, err := GetPlacetypeByName("planet") if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to load 'planet' placetype, %w", err) } pt_list := DescendantsForRoles(pl, roles) @@ -76,6 +108,7 @@ func PlacetypesForRoles(roles []string) ([]*WOFPlacetype, error) { return pt_list, nil } +// IsValidPlacetypeId returns a boolean value indicating whether 'name' is a known and valid placetype name. func IsValidPlacetype(name string) bool { for _, pt := range specification.Catalog() { @@ -88,6 +121,7 @@ func IsValidPlacetype(name string) bool { return false } +// IsValidPlacetypeId returns a boolean value indicating whether 'id' is a known and valid placetype ID. func IsValidPlacetypeId(id int64) bool { for str_id, _ := range specification.Catalog() { @@ -108,8 +142,81 @@ func IsValidPlacetypeId(id int64) bool { return false } +// Returns true is 'b' is an ancestor of 'a'. +func IsAncestor(a *WOFPlacetype, b *WOFPlacetype) bool { + + roles := []string{ + "common", + "optional", + "common_optional", + } + + str_roles := strings.Join(roles, "-") + key := fmt.Sprintf("%d_%d_%s_is_ancestor", a.Id, b.Id, str_roles) + + v, ok := relationships.Load(key) + + if ok { + return v.(bool) + } + + is_ancestor := false + + for _, ancestor := range AncestorsForRoles(a, roles) { + + if ancestor.Name == b.Name { + is_ancestor = true + break + } + } + + relationships.Store(key, is_ancestor) + return is_ancestor +} + +// Returns true is 'b' is a descendant of 'a'. +func IsDescendant(a *WOFPlacetype, b *WOFPlacetype) bool { + + roles := []string{ + "common", + "optional", + "common_optional", + } + + str_roles := strings.Join(roles, "-") + key := fmt.Sprintf("%d_%d_%s_is_descendant", a.Id, b.Id, str_roles) + + v, ok := relationships.Load(key) + + if ok { + return v.(bool) + } + + is_descendant := false + + for _, descendant := range DescendantsForRoles(a, roles) { + + if descendant.Name == b.Name { + is_descendant = true + break + } + } + + relationships.Store(key, is_descendant) + return is_descendant +} + +// Children returns the immediate child placetype of 'pt'. func Children(pt *WOFPlacetype) []*WOFPlacetype { + key := fmt.Sprintf("%d_children", pt.Id) + + v, ok := relationships.Load(key) + + if ok { + return v.([]*WOFPlacetype) + } + children := make([]*WOFPlacetype, 0) for _, details := range specification.Catalog() { @@ -123,7 +230,10 @@ func Children(pt *WOFPlacetype) []*WOFPlacetype { } } - return sortChildren(pt, children) + sorted := sortChildren(pt, children) + + relationships.Store(key, sorted) + return sorted } func sortChildren(pt *WOFPlacetype, all []*WOFPlacetype) []*WOFPlacetype { @@ -168,15 +278,27 @@ func sortChildren(pt *WOFPlacetype, all []*WOFPlacetype) []*WOFPlacetype { return kids } +// Descendants returns the descendants of role "common" for 'pt'. func Descendants(pt *WOFPlacetype) []*WOFPlacetype { return DescendantsForRoles(pt, []string{"common"}) } +// DescendantsForRoles returns the descendants matching any role in 'roles' for 'pt'. func DescendantsForRoles(pt *WOFPlacetype, roles []string) []*WOFPlacetype { + str_roles := strings.Join(roles, "-") + key := fmt.Sprintf("%d_descendants_%s", pt.Id, str_roles) + + v, ok := relationships.Load(key) + + if ok { + return v.([]*WOFPlacetype) + } + descendants := make([]*WOFPlacetype, 0) descendants = fetchDescendants(pt, roles, descendants) + relationships.Store(key, descendants) return descendants } @@ -235,15 +357,27 @@ func appendPlacetype(pt *WOFPlacetype, roles []string, others []*WOFPlacetype) [ return others } +// Ancestors returns the ancestors of role "common" for 'pt'. func Ancestors(pt *WOFPlacetype) []*WOFPlacetype { return AncestorsForRoles(pt, []string{"common"}) } +// AncestorsForRoles returns the ancestors matching any role in 'roles' for 'pt'. func AncestorsForRoles(pt *WOFPlacetype, roles []string) []*WOFPlacetype { + str_roles := strings.Join(roles, "-") + key := fmt.Sprintf("%d_ancestors_%s", pt.Id, str_roles) + + v, ok := relationships.Load(key) + + if ok { + return v.([]*WOFPlacetype) + } + ancestors := make([]*WOFPlacetype, 0) ancestors = fetchAncestors(pt, roles, ancestors) + relationships.Store(key, ancestors) return ancestors } diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/placetypes.json b/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/placetypes.json new file mode 100644 index 0000000..b9ca247 --- /dev/null +++ b/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/placetypes.json @@ -0,0 +1 @@ +{"102312321": {"role": "optional", "name": "microhood", "parent": [102312319], "names": {}}, "1159268867": {"role": "optional", "name": "enclosure", "parent": [102312325, 1159162575, 1159162573], "names": {}}, "1159268869": {"role": "optional", "name": "installation", "parent": [1159268867, 102312325, 1159162575, 1159162573, 102312327], "names": {}}, "102312327": {"role": "common_optional", "name": "building", "parent": [102312329, 1108906905, 102312331, 102312321, 102312319], "names": {}}, "102312329": {"role": "common_optional", "name": "address", "parent": [1108906905, 102312331, 102312321, 102312319], "names": {}}, "102312331": {"role": "common_optional", "name": "campus", "parent": [102312321, 102312319, 102312323, 102312317, 404221409], "names": {}}, "404528653": {"role": "common_optional", "name": "ocean", "parent": [102312341], "names": {}}, "102312335": {"role": "common_optional", "name": "empire", "parent": [102312309], "names": {}}, "421205763": {"role": "common_optional", "name": "borough", "parent": [102312317, 404221409], "names": {}}, "102312341": {"role": "common_optional", "name": "planet", "parent": [], "names": {}}, "1108906905": {"role": "optional", "name": "intersection", "parent": [102312331, 102312321, 102312319], "names": {}}, "102312325": {"role": "common_optional", "name": "venue", "parent": [1159162575, 1159162573, 1159162571, 102312327, 102312329, 1108906905, 102312331, 102312321, 102312319], "names": {}}, "1360666019": {"role": "optional", "name": "marketarea", "parent": [102312307], "names": {}}, "1159162571": {"role": "optional", "name": "wing", "parent": [102312327], "names": {}}, "102312323": {"role": "optional", "name": "macrohood", "parent": [421205763, 102312317], "names": {}}, "1108746739": {"role": "common_optional", "name": "constituency", "parent": [], "names": {}}, "102320821": {"role": "common_optional", "name": "dependency", "parent": [102312335], "names": {}}, "404528655": {"role": "common_optional", "name": "marinearea", "parent": [102312307, 102312309, 102312341], "names": {}}, "136057795": {"role": "common_optional", "name": "timezone", "parent": [102312307, 102312309, 102312341], "names": {}}, "1796730315": {"role": "optional", "name": "nation", "parent": [102312309, 102312335], "names": {}}, "1159162573": {"role": "optional", "name": "concourse", "parent": [1159162571, 102312327], "names": {}}, "1729783759": {"role": "optional", "name": "custom", "parent": [], "names": {}}, "470996387": {"role": "common_optional", "name": "postalcode", "parent": [102312317, 404221409, 102312313, 102312311], "names": {}}, "1159162575": {"role": "optional", "name": "arcade", "parent": [1159162573, 1159162571, 102312327], "names": {}}, "102371933": {"role": "optional", "name": "metroarea", "parent": [], "names": {}}, "404221409": {"role": "common_optional", "name": "localadmin", "parent": [102312313, 102312311], "names": {}}, "404221411": {"role": "optional", "name": "macroregion", "parent": [102320821, 102322043, 102312307], "names": {}}, "404221413": {"role": "optional", "name": "macrocounty", "parent": [102312311], "names": {}}, "102312307": {"role": "common", "name": "country", "parent": [102312309, 102312335], "names": {}}, "102312309": {"role": "common", "name": "continent", "parent": [102312341], "names": {}}, "102312311": {"role": "common", "name": "region", "parent": [404221411, 102320821, 102322043, 102312307], "names": {}}, "102312313": {"role": "common_optional", "name": "county", "parent": [404221413, 102312311], "names": {}}, "102322043": {"role": "common_optional", "name": "disputed", "parent": [102312307], "names": {}}, "102312317": {"role": "common", "name": "locality", "parent": [404221409, 102312313, 102312311], "names": {}}, "102312319": {"role": "common", "name": "neighbourhood", "parent": [102312323, 421205763, 102312317], "names": {"eng_p": ["neighbourhood", "neighborhood"]}}} diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/placetypes/spec.go b/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/placetypes/spec.go deleted file mode 100644 index f7eca36..0000000 --- a/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/placetypes/spec.go +++ /dev/null @@ -1,6 +0,0 @@ -package placetypes - -/* https://raw.githubusercontent.com/whosonfirst/whosonfirst-placetypes/master/data/placetypes-spec-latest.json */ -/* This file was generated by robots (cmd/mk-spec.go) at 2021-02-20 01:30:23.952814 +0000 UTC */ - -const Specification string = `{"102312321": {"role": "optional", "name": "microhood", "parent": [102312319], "names": {}}, "1159268867": {"role": "optional", "name": "enclosure", "parent": [102312325, 1159162575, 1159162573], "names": {}}, "1159268869": {"role": "optional", "name": "installation", "parent": [1159268867, 102312325, 1159162575, 1159162573, 102312327], "names": {}}, "102312327": {"role": "common_optional", "name": "building", "parent": [102312329, 1108906905, 102312331, 102312321, 102312319], "names": {}}, "102312329": {"role": "common_optional", "name": "address", "parent": [1108906905, 102312331, 102312321, 102312319], "names": {}}, "102312331": {"role": "common_optional", "name": "campus", "parent": [102312321, 102312319, 102312323, 102312317, 404221409], "names": {}}, "404528653": {"role": "common_optional", "name": "ocean", "parent": [102312341], "names": {}}, "102312335": {"role": "common_optional", "name": "empire", "parent": [102312309], "names": {}}, "421205763": {"role": "common_optional", "name": "borough", "parent": [102312317, 404221409], "names": {}}, "102312341": {"role": "common_optional", "name": "planet", "parent": [], "names": {}}, "1108906905": {"role": "optional", "name": "intersection", "parent": [102312331, 102312321, 102312319], "names": {}}, "102312325": {"role": "common_optional", "name": "venue", "parent": [1159162575, 1159162573, 1159162571, 102312327, 102312329, 1108906905, 102312331, 102312321, 102312319], "names": {}}, "1360666019": {"role": "optional", "name": "marketarea", "parent": [102312307], "names": {}}, "102312323": {"role": "optional", "name": "macrohood", "parent": [421205763, 102312317], "names": {}}, "1108746739": {"role": "common_optional", "name": "constituency", "parent": [], "names": {}}, "102320821": {"role": "common_optional", "name": "dependency", "parent": [102312335], "names": {}}, "404528655": {"role": "common_optional", "name": "marinearea", "parent": [102312307, 102312309, 102312341], "names": {}}, "136057795": {"role": "common_optional", "name": "timezone", "parent": [102312307, 102312309, 102312341], "names": {}}, "1159162571": {"role": "optional", "name": "wing", "parent": [102312327], "names": {}}, "1159162573": {"role": "optional", "name": "concourse", "parent": [1159162571, 102312327], "names": {}}, "1729783759": {"role": "optional", "name": "custom", "parent": [], "names": {}}, "470996387": {"role": "common_optional", "name": "postalcode", "parent": [102312317, 404221409, 102312313, 102312311], "names": {}}, "1159162575": {"role": "optional", "name": "arcade", "parent": [1159162573, 1159162571, 102312327], "names": {}}, "102371933": {"role": "optional", "name": "metroarea", "parent": [], "names": {}}, "404221409": {"role": "common_optional", "name": "localadmin", "parent": [102312313, 102312311], "names": {}}, "404221411": {"role": "optional", "name": "macroregion", "parent": [102320821, 102322043, 102312307], "names": {}}, "404221413": {"role": "optional", "name": "macrocounty", "parent": [102312311], "names": {}}, "102312307": {"role": "common", "name": "country", "parent": [102312309, 102312335], "names": {}}, "102312309": {"role": "common", "name": "continent", "parent": [102312341], "names": {}}, "102312311": {"role": "common", "name": "region", "parent": [404221411, 102320821, 102322043, 102312307], "names": {}}, "102312313": {"role": "common_optional", "name": "county", "parent": [404221413, 102312311], "names": {}}, "102322043": {"role": "common_optional", "name": "disputed", "parent": [102312307], "names": {}}, "102312317": {"role": "common", "name": "locality", "parent": [404221409, 102312313, 102312311], "names": {}}, "102312319": {"role": "common", "name": "neighbourhood", "parent": [102312323, 421205763, 102312317], "names": {"eng_p": ["neighbourhood", "neighborhood"]}}}` diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/specification.go b/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/specification.go index 48ae7e6..abbb5a3 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/specification.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-placetypes/specification.go @@ -1,42 +1,43 @@ package placetypes import ( + "bytes" + "embed" "encoding/json" - "errors" - "github.com/whosonfirst/go-whosonfirst-placetypes/placetypes" + "fmt" "io" - "io/ioutil" "strconv" "sync" ) +//go:embed placetypes.json +var fs embed.FS + type WOFPlacetypeSpecification struct { catalog map[string]WOFPlacetype mu *sync.RWMutex } func DefaultWOFPlacetypeSpecification() (*WOFPlacetypeSpecification, error) { - return NewWOFPlacetypeSpecification([]byte(placetypes.Specification)) -} - -func NewWOFPlacetypeSpecificationWithReader(r io.Reader) (*WOFPlacetypeSpecification, error) { - body, err := ioutil.ReadAll(r) + r, err := fs.Open("placetypes.json") if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to open placetypes, %w", err) } - return NewWOFPlacetypeSpecification(body) + return NewWOFPlacetypeSpecificationWithReader(r) } -func NewWOFPlacetypeSpecification(body []byte) (*WOFPlacetypeSpecification, error) { +func NewWOFPlacetypeSpecificationWithReader(r io.Reader) (*WOFPlacetypeSpecification, error) { var catalog map[string]WOFPlacetype - err := json.Unmarshal(body, &catalog) + + dec := json.NewDecoder(r) + err := dec.Decode(&catalog) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to decode reader, %w", err) } mu := new(sync.RWMutex) @@ -49,6 +50,12 @@ func NewWOFPlacetypeSpecification(body []byte) (*WOFPlacetypeSpecification, erro return spec, nil } +func NewWOFPlacetypeSpecification(body []byte) (*WOFPlacetypeSpecification, error) { + + r := bytes.NewReader(body) + return NewWOFPlacetypeSpecificationWithReader(r) +} + func (spec *WOFPlacetypeSpecification) GetPlacetypeByName(name string) (*WOFPlacetype, error) { // spec.mu.RLock() @@ -71,7 +78,7 @@ func (spec *WOFPlacetypeSpecification) GetPlacetypeByName(name string) (*WOFPlac } } - return nil, errors.New("Invalid placetype") + return nil, fmt.Errorf("Invalid placetype") } func (spec *WOFPlacetypeSpecification) GetPlacetypeById(id int64) (*WOFPlacetype, error) { @@ -95,7 +102,7 @@ func (spec *WOFPlacetypeSpecification) GetPlacetypeById(id int64) (*WOFPlacetype } } - return nil, errors.New("Invalid placetype") + return nil, fmt.Errorf("Invalid placetype") } func (spec *WOFPlacetypeSpecification) AppendPlacetypeSpecification(other_spec *WOFPlacetypeSpecification) error { @@ -105,7 +112,7 @@ func (spec *WOFPlacetypeSpecification) AppendPlacetypeSpecification(other_spec * err := spec.AppendPlacetype(pt) if err != nil { - return err + return fmt.Errorf("Failed to append placetype %v, %w", pt, err) } } @@ -120,13 +127,13 @@ func (spec *WOFPlacetypeSpecification) AppendPlacetype(pt WOFPlacetype) error { existing_pt, _ := spec.GetPlacetypeById(pt.Id) if existing_pt != nil { - return errors.New("Placetype ID already registered") + return fmt.Errorf("Placetype ID already registered") } existing_pt, _ = spec.GetPlacetypeByName(pt.Name) if existing_pt != nil { - return errors.New("Placetype name already registered") + return fmt.Errorf("Placetype name already registered") } for _, pid := range pt.Parent { @@ -134,7 +141,7 @@ func (spec *WOFPlacetypeSpecification) AppendPlacetype(pt WOFPlacetype) error { _, err := spec.GetPlacetypeById(pid) if err != nil { - return err + return fmt.Errorf("Failed to get placetype by ID %d, %w", pid, err) } } diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/README.md b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/README.md index 8c66bfb..98ddfc0 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/README.md +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/README.md @@ -1,19 +1,22 @@ # go-whosonfirst-spatial +Go package defining interfaces for Who's On First specific spatial operations. + ## Documentation Documentation, particularly proper Go documentation, is incomplete at this time. ## Motivation -`go-whosonfirst-spatial` is an attempt to de-couple the various components that make up the [go-whosonfirst-pip-v2](https://github.com/whosonfirst/go-whosonfirst-pip-v2) package – indexing, storage, querying and serving – in to separate packages in order to allow for more flexibility. +The goal of the `go-whosonfirst-spatial` package is to de-couple the various components that made up the now-deprecated [go-whosonfirst-pip-v2](https://github.com/whosonfirst/go-whosonfirst-pip-v2) package – indexing, storage, querying and serving – in to separate packages in order to allow for more flexibility. It is the "base" package that defines provider-agnostic, but WOF-specific, interfaces for a limited set of spatial queries and reading properties. -These interfaces are then implemented in full or in part by provider-specific classes. For example, an in-memory RTree index or SQLite: +These interfaces are then implemented in full or in part by provider-specific classes. For example, an in-memory RTree index or a SQLite database or even a Protomaps database: * https://github.com/whosonfirst/go-whosonfirst-spatial-rtree * https://github.com/whosonfirst/go-whosonfirst-spatial-sqlite +* https://github.com/whosonfirst/go-whosonfirst-spatial-pmtiles Building on that there are equivalent base packages for "server" implementations, like: @@ -30,92 +33,97 @@ import ( Here is a concrete example, implementing a point-in-polygon service over HTTP using a SQLite backend: +* https://github.com/whosonfirst/go-whosonfirst-spatial-www/blob/main/application/server * https://github.com/whosonfirst/go-whosonfirst-spatial-www-sqlite/blob/main/cmd/server/main.go It is part of the overall goal of: * Staying out people's database or delivery choices (or needs) * Supporting as many databases (and delivery (and indexing) choices) as possible -* Not making database B a dependency (in the Go code) in order to use database A, as in not bundling everything in a single mono-repo that becomes bigger and has more requirements over time. - -That's the goal, anyway. I am still working through the implementation details. - -Functionally the `go-whosonfirst-spatial-` packages should be equivalent to `go-whosonfirst-pip-v2` as in there won't be any functionality _removed_. - -## Example - -``` -import ( - "context" - "encoding/json" - "fmt" - "github.com/whosonfirst/go-whosonfirst-spatial/app" - "github.com/whosonfirst/go-whosonfirst-spatial/filter" - "github.com/whosonfirst/go-whosonfirst-spatial/flags" - "github.com/whosonfirst/go-whosonfirst-spatial/geo" - _ "github.com/whosonfirst/go-whosonfirst-spatial-rtree" -) - -func main() { - - fl, _ := flags.CommonFlags() - flags.Parse(fl) - - flags.ValidateCommonFlags(fl) +* Not making database `B` a dependency (in the Go code) in order to use database `A`, as in not bundling everything in a single mono-repo that becomes bigger and has more requirements over time. - paths := fl.Args() - - ctx := context.Background() +Importantly this package does not implement any actual spatial functionality. It defines the interfaces that are implemented by other packages which allows code to function without the need to consider the underlying mechanics of how spatial operations are being performed. - spatial_app, _ := app.NewSpatialApplicationWithFlagSet(ctx, fl) - spatial_app.IndexPaths(ctx, paths...) +The layout of this package remains in flux and is likely to change. Things have almost settled but not quite yet. - c, _ := geo.NewCoordinate(-122.395229, 37.794906) - f, _ := filter.NewSPRFilter() +## Interfaces - spatial_db := spatial_app.SpatialDatabase - spatial_results, _ := spatial_db.PointInPolygon(ctx, c, f) +### SpatialIndex - body, _ := json.Marshal(spatial_results) - fmt.Println(string(body)) +``` +type SpatialIndex interface { + IndexFeature(context.Context, []byte) error + RemoveFeature(context.Context, string) error + PointInPolygon(context.Context, *orb.Point, ...Filter) (spr.StandardPlacesResults, error) + PointInPolygonCandidates(context.Context, *orb.Point, ...Filter) ([]*PointInPolygonCandidate, error) + PointInPolygonWithChannels(context.Context, chan spr.StandardPlacesResult, chan error, chan bool, *orb.Point, ...Filter) + PointInPolygonCandidatesWithChannels(context.Context, chan *PointInPolygonCandidate, chan error, chan bool, *orb.Point, ...Filter) + Disconnect(context.Context) error } ``` -_Error handling omitted for brevity._ - -## Concepts - -### Applications +_Where `orb.*` and `spr.*` refer to the [paulmach/orb](https://github.com/paulmach/orb) and [whosonfirst/go-whosonfirst-flags](https://github.com/whosonfirst/go-whosonfirst-flags) packages respectively._ -_Please write me_ +### SpatialDatabase -### Database - -_Please write me_ - -### Filters - -_Please write me_ +``` +type SpatialDatabase interface { + reader.Reader + writer.Writer + spatial.SpatialIndex +} +``` -### Indices +_Where `reader.Reader` and `writer.Writer` are the [whosonfirst/go-reader](https://pkg.go.dev/github.com/whosonfirst/go-reader#Reader) and [whosonfirst/go-writer](https://pkg.go.dev/github.com/whosonfirst/go-writer#Writer) interfaces, respectively._ -_Please write me_ +### Filter -### Standard Places Response (SPR) +``` +type Filter interface { + HasPlacetypes(flags.PlacetypeFlag) bool + MatchesInception(flags.DateFlag) bool + MatchesCessation(flags.DateFlag) bool + IsCurrent(flags.ExistentialFlag) bool + IsDeprecated(flags.ExistentialFlag) bool + IsCeased(flags.ExistentialFlag) bool + IsSuperseded(flags.ExistentialFlag) bool + IsSuperseding(flags.ExistentialFlag) bool + IsAlternateGeometry(flags.AlternateGeometryFlag) bool + HasAlternateGeometry(flags.AlternateGeometryFlag) bool +} +``` -_Please write me_ +_Where `flags.*` refers to the [whosonfirst/go-whosonfirst-flags](https://github.com/whosonfirst/go-whosonfirst-flags) package._ ## Implementations * https://github.com/whosonfirst/go-whosonfirst-spatial-rtree * https://github.com/whosonfirst/go-whosonfirst-spatial-sqlite +* https://github.com/whosonfirst/go-whosonfirst-spatial-pmtiles ## Servers and clients +### WWW + * https://github.com/whosonfirst/go-whosonfirst-spatial-www +* https://github.com/whosonfirst/go-whosonfirst-spatial-www-sqlite +* https://github.com/whosonfirst/go-whosonfirst-spatial-www-pmtiles + +### gRPC + * https://github.com/whosonfirst/go-whosonfirst-spatial-grpc +* https://github.com/whosonfirst/go-whosonfirst-spatial-grpc-sqlite +* https://github.com/whosonfirst/go-whosonfirst-spatial-grpc-pmtiles -## Services +## Services and Operations * https://github.com/whosonfirst/go-whosonfirst-spatial-pip -* https://github.com/whosonfirst/go-whosonfirst-spatial-hierarchy \ No newline at end of file +* https://github.com/whosonfirst/go-whosonfirst-spatial-hierarchy + +## See also + +* https://github.com/whosonfirst/go-whosonfirst-spr +* https://github.com/whosonfirst/go-whosonfirst-flags +* https://github.com/whosonfirst/go-reader +* https://github.com/whosonfirst/go-writer +* https://github.com/paulmach/orb \ No newline at end of file diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/common.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/common.go index 96fb6b5..52b7213 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/common.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/common.go @@ -16,7 +16,7 @@ func CommonFlags() (*flag.FlagSet, error) { err := AppendCommonFlags(fs) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to append common application flags, %w", err) } return fs, nil @@ -29,44 +29,44 @@ func AppendCommonFlags(fs *flag.FlagSet) error { available_databases := database.Schemes() desc_databases := fmt.Sprintf("A valid whosonfirst/go-whosonfirst-spatial/data.SpatialDatabase URI. options are: %s", available_databases) - fs.String(SPATIAL_DATABASE_URI, "", desc_databases) + fs.String(SpatialDatabaseURIFlag, "", desc_databases) available_readers := reader.Schemes() desc_readers := fmt.Sprintf("A valid whosonfirst/go-reader.Reader URI. Available options are: %s", available_readers) - fs.String(PROPERTIES_READER_URI, "", desc_readers) + fs.String(PropertiesReaderURIFlag, "", fmt.Sprintf("%s. If the value is {spatial-database-uri} then the value of the '-spatial-database-uri' implements the reader.Reader interface and will be used.", desc_readers)) fs.Bool(IS_WOF, true, "Input data is WOF-flavoured GeoJSON. (Pass a value of '0' or 'false' if you need to index non-WOF documents.") - fs.Bool(ENABLE_CUSTOM_PLACETYPES, false, "Enable wof:placetype values that are not explicitly defined in the whosonfirst/go-whosonfirst-placetypes repository.") + fs.Bool(EnableCustomPlacetypesFlag, false, "Enable wof:placetype values that are not explicitly defined in the whosonfirst/go-whosonfirst-placetypes repository.") // Pending changes in the app/placetypes.go package to support // alternate sources (20210324/thisisaaronland) // fs.String(CUSTOM_PLACETYPES_SOURCE, "", "...") - fs.String(CUSTOM_PLACETYPES, "", "A JSON-encoded string containing custom placetypes defined using the syntax described in the whosonfirst/go-whosonfirst-placetypes repository.") + fs.String(CustomPlacetypesFlag, "", "A JSON-encoded string containing custom placetypes defined using the syntax described in the whosonfirst/go-whosonfirst-placetypes repository.") - fs.Bool(VERBOSE, false, "Be chatty.") + fs.Bool(VerboseFlag, false, "Be chatty.") return nil } func ValidateCommonFlags(fs *flag.FlagSet) error { - spatial_database_uri, err := lookup.StringVar(fs, SPATIAL_DATABASE_URI) + spatial_database_uri, err := lookup.StringVar(fs, SpatialDatabaseURIFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", SpatialDatabaseURIFlag, err) } if spatial_database_uri == "" { - return fmt.Errorf("Invalid or missing -%s flag", SPATIAL_DATABASE_URI) + return fmt.Errorf("Invalid or missing -%s flag", SpatialDatabaseURIFlag) } - _, err = lookup.StringVar(fs, PROPERTIES_READER_URI) + _, err = lookup.StringVar(fs, PropertiesReaderURIFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", PropertiesReaderURIFlag, err) } return nil diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/flags.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/flags.go index a5dc21d..13eb6a3 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/flags.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/flags.go @@ -1,43 +1,89 @@ package flags -const ALTERNATE_GEOMETRIES string = "alternate-geometry" +const AlternateGeometriesFlag string = "alternate-geometry" -const CESSATION_DATE string = "cessation-date" +const CessationDateFlag string = "cessation-date" -const CUSTOM_PLACETYPES string = "custom-placetypes" +const CustomPlacetypesFlag string = "custom-placetypes" -const CUSTOM_PLACETYPES_SOURCE string = "custom-placetypes-source" +const CustomPlacetypesSourceFlag string = "custom-placetypes-source" -const ENABLE_CUSTOM_PLACETYPES string = "enable-custom-placetypes" +const EnableCustomPlacetypesFlag string = "enable-custom-placetypes" -const GEOMETRIES string = "geometries" +const GeometriesFlag string = "geometries" -const INCEPTION_DATE string = "inception-date" +const InceptionDateFlag string = "inception-date" -const IS_CEASED string = "is-ceased" +const IsCeasedFlag string = "is-ceased" -const IS_CURRENT string = "is-current" +const IsCurrentFlag string = "is-current" -const IS_DEPRECATED string = "is-deprecated" +const IsDeprecatedFlag string = "is-deprecated" -const IS_SUPERSEDED string = "is-superseded" +const IsSupersededFlag string = "is-superseded" -const IS_SUPERSEDING string = "is-superseding" +const IsSupersedingFlag string = "is-superseding" -const ITERATOR_URI string = "iterator-uri" +const IteratorURIFlag string = "iterator-uri" -const LATITUDE string = "latitude" +const LatitudeFlag string = "latitude" -const LONGITUDE string = "longitude" +const LongitudeFlag string = "longitude" -const PLACETYPES string = "placetype" +const PlacetypeFlag string = "placetype" -const PROPERTIES string = "property" +const PropertyFlag string = "property" -const SPATIAL_DATABASE_URI string = "spatial-database-uri" +const SpatialDatabaseURIFlag string = "spatial-database-uri" -const PROPERTIES_READER_URI string = "properties-reader-uri" +const PropertiesReaderURIFlag string = "properties-reader-uri" -const VERBOSE string = "verbose" +const VerboseFlag string = "verbose" + +const SortURIFlag string = "sort-uri" + +// Deprecated. These will be removed once this package reaches v1.0.0 + +const ALTERNATE_GEOMETRIES string = AlternateGeometriesFlag + +const CESSATION_DATE string = CessationDateFlag + +const CUSTOM_PLACETYPES string = CustomPlacetypesFlag + +const CUSTOM_PLACETYPES_SOURCE string = CustomPlacetypesSourceFlag + +const ENABLE_CUSTOM_PLACETYPES string = EnableCustomPlacetypesFlag + +const GEOMETRIES string = GeometriesFlag + +const INCEPTION_DATE string = InceptionDateFlag + +const IS_CEASED string = IsCeasedFlag + +const IS_CURRENT string = IsCurrentFlag + +const IS_DEPRECATED string = IsDeprecatedFlag + +const IS_SUPERSEDED string = IsSupersededFlag + +const IS_SUPERSEDING string = IsSupersedingFlag + +const ITERATOR_URI string = IteratorURIFlag + +const LATITUDE string = LatitudeFlag + +const LONGITUDE string = LongitudeFlag + +const PLACETYPES string = PlacetypeFlag + +const PROPERTIES string = PropertyFlag + +const SPATIAL_DATABASE_URI string = SpatialDatabaseURIFlag + +const PROPERTIES_READER_URI string = PropertiesReaderURIFlag + +const VERBOSE string = VerboseFlag const IS_WOF string = "is-wof" + +const SORT string = SortURIFlag diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/iterator.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/iterator.go index 5cd5da9..03d80da 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/iterator.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/iterator.go @@ -17,17 +17,17 @@ func AppendIndexingFlags(fs *flag.FlagSet) error { valid_modes := strings.Join(modes, ", ") desc_modes := fmt.Sprintf("A valid whosonfirst/go-whosonfirst-iterate/v2 URI. Supported schemes are: %s.", valid_modes) - fs.String(ITERATOR_URI, "repo://", desc_modes) + fs.String(IteratorURIFlag, "repo://", desc_modes) return nil } func ValidateIndexingFlags(fs *flag.FlagSet) error { - _, err := lookup.StringVar(fs, ITERATOR_URI) + _, err := lookup.StringVar(fs, IteratorURIFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", IteratorURIFlag, err) } return nil diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/query.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/query.go index 3128788..dacd37c 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/query.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/flags/query.go @@ -1,8 +1,8 @@ package flags import ( - "errors" "flag" + "fmt" "github.com/sfomuseum/go-flags/lookup" "github.com/sfomuseum/go-flags/multi" "github.com/whosonfirst/go-whosonfirst-spatial/geo" @@ -10,109 +10,106 @@ import ( func AppendQueryFlags(fs *flag.FlagSet) error { - fs.Float64(LATITUDE, 0.0, "A valid latitude.") - fs.Float64(LONGITUDE, 0.0, "A valid longitude.") + fs.Float64(LatitudeFlag, 0.0, "A valid latitude.") + fs.Float64(LongitudeFlag, 0.0, "A valid longitude.") - fs.String(GEOMETRIES, "all", "Valid options are: all, alt, default.") + fs.String(GeometriesFlag, "all", "Valid options are: all, alt, default.") - fs.String(INCEPTION_DATE, "", "A valid EDTF date string.") - fs.String(CESSATION_DATE, "", "A valid EDTF date string.") + fs.String(InceptionDateFlag, "", "A valid EDTF date string.") + fs.String(CessationDateFlag, "", "A valid EDTF date string.") var props multi.MultiString - fs.Var(&props, PROPERTIES, "One or more Who's On First properties to append to each result.") + fs.Var(&props, PropertyFlag, "One or more Who's On First properties to append to each result.") var placetypes multi.MultiString - fs.Var(&placetypes, PLACETYPES, "One or more place types to filter results by.") + fs.Var(&placetypes, PlacetypeFlag, "One or more place types to filter results by.") var alt_geoms multi.MultiString - fs.Var(&alt_geoms, ALTERNATE_GEOMETRIES, "One or more alternate geometry labels (wof:alt_label) values to filter results by.") + fs.Var(&alt_geoms, AlternateGeometriesFlag, "One or more alternate geometry labels (wof:alt_label) values to filter results by.") var is_current multi.MultiInt64 - fs.Var(&is_current, IS_CURRENT, "One or more existential flags (-1, 0, 1) to filter results by.") + fs.Var(&is_current, IsCurrentFlag, "One or more existential flags (-1, 0, 1) to filter results by.") var is_ceased multi.MultiInt64 - fs.Var(&is_ceased, IS_CEASED, "One or more existential flags (-1, 0, 1) to filter results by.") + fs.Var(&is_ceased, IsCeasedFlag, "One or more existential flags (-1, 0, 1) to filter results by.") var is_deprecated multi.MultiInt64 - fs.Var(&is_deprecated, IS_DEPRECATED, "One or more existential flags (-1, 0, 1) to filter results by.") + fs.Var(&is_deprecated, IsDeprecatedFlag, "One or more existential flags (-1, 0, 1) to filter results by.") var is_superseded multi.MultiInt64 - fs.Var(&is_superseded, IS_SUPERSEDED, "One or more existential flags (-1, 0, 1) to filter results by.") + fs.Var(&is_superseded, IsSupersededFlag, "One or more existential flags (-1, 0, 1) to filter results by.") var is_superseding multi.MultiInt64 - fs.Var(&is_superseding, IS_SUPERSEDING, "One or more existential flags (-1, 0, 1) to filter results by.") + fs.Var(&is_superseding, IsSupersedingFlag, "One or more existential flags (-1, 0, 1) to filter results by.") + + var sort multi.MultiString + fs.Var(&sort, SortURIFlag, "Zero or more whosonfirst/go-whosonfirst-spr/sort URIs.") return nil } func ValidateQueryFlags(fs *flag.FlagSet) error { - lat, err := lookup.Float64Var(fs, LATITUDE) + lat, err := lookup.Float64Var(fs, LatitudeFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", LatitudeFlag, err) } - lon, err := lookup.Float64Var(fs, LONGITUDE) + lon, err := lookup.Float64Var(fs, LongitudeFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", LongitudeFlag, err) } if !geo.IsValidLatitude(lat) { - return errors.New("Invalid latitude") + return fmt.Errorf("Invalid latitude") } if !geo.IsValidLongitude(lon) { - return errors.New("Invalid longitude") - } - - _, err = lookup.StringVar(fs, GEOMETRIES) - - if err != nil { - return err + return fmt.Errorf("Invalid longitude") } - _, err = lookup.MultiStringVar(fs, ALTERNATE_GEOMETRIES) + _, err = lookup.StringVar(fs, GeometriesFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", GeometriesFlag, err) } - _, err = lookup.MultiInt64Var(fs, IS_CURRENT) + _, err = lookup.MultiStringVar(fs, AlternateGeometriesFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", AlternateGeometriesFlag, err) } - _, err = lookup.MultiInt64Var(fs, IS_CEASED) + _, err = lookup.MultiInt64Var(fs, IsCurrentFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", IsCurrentFlag, err) } - _, err = lookup.MultiInt64Var(fs, IS_DEPRECATED) + _, err = lookup.MultiInt64Var(fs, IsCeasedFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", IsCeasedFlag, err) } - _, err = lookup.MultiInt64Var(fs, IS_DEPRECATED) + _, err = lookup.MultiInt64Var(fs, IsDeprecatedFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", IsDeprecatedFlag, err) } - _, err = lookup.MultiInt64Var(fs, IS_SUPERSEDED) + _, err = lookup.MultiInt64Var(fs, IsSupersededFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", IsSupersededFlag, err) } - _, err = lookup.MultiInt64Var(fs, IS_SUPERSEDING) + _, err = lookup.MultiInt64Var(fs, IsSupersedingFlag) if err != nil { - return err + return fmt.Errorf("Failed to lookup %s flag, %w", IsSupersedingFlag, err) } return nil diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/properties.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/properties.go index ca5a628..c7a3647 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/properties.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/properties.go @@ -33,7 +33,7 @@ func PropertiesResponseResultsWithStandardPlacesResults(ctx context.Context, opt fh, err := opts.Reader.Read(ctx, path) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to open %s for reading, %w", path, err) } defer fh.Close() @@ -41,13 +41,13 @@ func PropertiesResponseResultsWithStandardPlacesResults(ctx context.Context, opt source, err := io.ReadAll(fh) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to read body from %s, %w", path, err) } target, err := json.Marshal(r) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to marshal %s, %w", path, err) } target, err = AppendPropertiesWithJSON(ctx, opts, source, target) @@ -60,7 +60,7 @@ func PropertiesResponseResultsWithStandardPlacesResults(ctx context.Context, opt err = json.Unmarshal(target, &props) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to unmarshal props for %s, %w", path, err) } new_results[idx] = props @@ -132,7 +132,7 @@ func AppendPropertiesWithJSON(ctx context.Context, opts *PropertiesResponseOptio target, err = sjson.SetBytes(target, set_path, v.Value()) if err != nil { - return nil, err + return nil, fmt.Errorf("Failed to set %s, %w", set_path, err) } } } diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/timer/timer.go b/vendor/github.com/whosonfirst/go-whosonfirst-spatial/timer/timer.go deleted file mode 100644 index 424a6b0..0000000 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spatial/timer/timer.go +++ /dev/null @@ -1,61 +0,0 @@ -package timer - -import ( - "context" - "fmt" - "sync" - "time" -) - -type Timing struct { - Created time.Time - Description string - Duration time.Duration -} - -func (t *Timing) String() string { - return fmt.Sprintf("%s: %v", t.Description, t.Duration) -} - -type Timer struct { - mu *sync.RWMutex - Timings map[string][]*Timing -} - -func NewTimer() *Timer { - - timings := make(map[string][]*Timing) - mu := new(sync.RWMutex) - - t := &Timer{ - mu: mu, - Timings: timings, - } - - return t -} - -func (t *Timer) Add(ctx context.Context, group string, description string, duration time.Duration) error { - - now := time.Now() - - tm := &Timing{ - Created: now, - Description: description, - Duration: duration, - } - - t.mu.Lock() - defer t.mu.Unlock() - - timings, ok := t.Timings[group] - - if !ok { - timings = make([]*Timing, 0) - } - - timings = append(timings, tm) - t.Timings[group] = timings - - return nil -} diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/doc.go b/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/doc.go index e340fce..6b0ce7b 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/doc.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/doc.go @@ -8,4 +8,3 @@ // // For a concrete example of a package that implements the `SPR` have a look at the [go-whosonfirst-sqlite-spr](https://github.com/whosonfirst/go-whosonfirst-sqlite-spr) package. package spr - diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/spr.go b/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/spr.go index 1d89c28..e21c9c0 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/spr.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/spr.go @@ -13,7 +13,7 @@ type StandardPlacesResult interface { ParentId() string // The name of the place result Name() string - // The Who's On First placetype of the place result + // The Who's On First placetype of the place result Placetype() string // The two-letter country code of the place result Country() string @@ -21,39 +21,39 @@ type StandardPlacesResult interface { Repo() string // The relative path for the Who's On First record associated with the place result Path() string - // The fully-qualified URI (URL) for the Who's On First record associated with the place result + // The fully-qualified URI (URL) for the Who's On First record associated with the place result URI() string // The EDTF inception date of the place result Inception() *edtf.EDTFDate - // The EDTF cessation date of the place result + // The EDTF cessation date of the place result Cessation() *edtf.EDTFDate // The latitude for the principal centroid (typically "label") of the place result Latitude() float64 - // The longitude for the principal centroid (typically "label") of the place result + // The longitude for the principal centroid (typically "label") of the place result Longitude() float64 // The minimum latitude of the bounding box of the place result MinLatitude() float64 - // The minimum longitude of the bounding box of the place result + // The minimum longitude of the bounding box of the place result MinLongitude() float64 - // The maximum latitude of the bounding box of the place result + // The maximum latitude of the bounding box of the place result MaxLatitude() float64 - // The maximum longitude of the bounding box of the place result + // The maximum longitude of the bounding box of the place result MaxLongitude() float64 // The Who's On First "existential" flag denoting whether the place result is "current" or not IsCurrent() flags.ExistentialFlag - // The Who's On First "existential" flag denoting whether the place result is "ceased" or not + // The Who's On First "existential" flag denoting whether the place result is "ceased" or not IsCeased() flags.ExistentialFlag - // The Who's On First "existential" flag denoting whether the place result is superseded or not + // The Who's On First "existential" flag denoting whether the place result is superseded or not IsDeprecated() flags.ExistentialFlag - // The Who's On First "existential" flag denoting whether the place result has been superseded + // The Who's On First "existential" flag denoting whether the place result has been superseded IsSuperseded() flags.ExistentialFlag - // The Who's On First "existential" flag denoting whether the place result supersedes other records + // The Who's On First "existential" flag denoting whether the place result supersedes other records IsSuperseding() flags.ExistentialFlag // The list of Who's On First IDs that supersede the place result SupersededBy() []int64 - // The list of Who's On First IDs that are superseded by the place result + // The list of Who's On First IDs that are superseded by the place result Supersedes() []int64 - // The list of Who's On First IDs that are ancestors of the place result + // The list of Who's On First IDs that are ancestors of the place result BelongsTo() []int64 // The Unix timestamp indicating when the place result was last modified LastModified() int64 diff --git a/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/whosonfirst_alt.go b/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/whosonfirst_alt.go index cd1817b..c54f0dd 100644 --- a/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/whosonfirst_alt.go +++ b/vendor/github.com/whosonfirst/go-whosonfirst-spr/v2/whosonfirst_alt.go @@ -16,6 +16,7 @@ import ( type WOFAltStandardPlacesResult struct { StandardPlacesResult `json:",omitempty"` WOFId string `json:"wof:id"` + WOFParentId int64 `json:wof:parent_id"` WOFName string `json:"wof:name"` WOFPlacetype string `json:"wof:placetype"` MZLatitude float64 `json:"mz:latitude"` @@ -102,6 +103,7 @@ func WhosOnFirstAltSPR(f []byte) (StandardPlacesResult, error) { spr := WOFAltStandardPlacesResult{ WOFId: str_id, + WOFParentId: -1, WOFPlacetype: "alt", WOFName: name, MZLatitude: lat, diff --git a/vendor/github.com/whosonfirst/go-writer/v3/io.go b/vendor/github.com/whosonfirst/go-writer/v3/io.go index c93b54c..606aec3 100644 --- a/vendor/github.com/whosonfirst/go-writer/v3/io.go +++ b/vendor/github.com/whosonfirst/go-writer/v3/io.go @@ -14,6 +14,7 @@ const IOWRITER_TARGET_KEY string = "github.com/whosonfirst/go-writer#io_writer" // IOWriter is a struct that implements the `Writer` interface for writing documents to an `io.Writer` instance. type IOWriter struct { Writer + writer io.Writer } func init() { @@ -26,7 +27,7 @@ func init() { } } -// NewIOWriter returns a new `IOWriter` instance for writing documents to the current working directory +// NewIOWriter returns a new `IOWriter` instance for writing documents to an `io.Writer` instance // configured by 'uri' in the form of: // // io:// @@ -34,40 +35,58 @@ func init() { // In order to assign the actual `io.Writer` instance to use you will need to call the `SetIOWriterWithContext` // method and pass the resultant `context.Context` instance to the `Write` method. func NewIOWriter(ctx context.Context, uri string) (Writer, error) { - wr := &IOWriter{} - return wr, nil + io_wr := &IOWriter{} + return io_wr, nil } -// Write copies the content of 'fh' to 'path'. It is assumed that 'ctx' contains a valid `io.Writer` instance -// that has been assigned by the `SetIOWriterWithContext` method. -func (wr *IOWriter) Write(ctx context.Context, path string, fh io.ReadSeeker) (int64, error) { +// NewIOWriter returns a new `IOWriter` instance for writing documents to 'wr'. +func NewIOWriterWithWriter(ctx context.Context, wr io.Writer) (Writer, error) { + io_wr := &IOWriter{ + writer: wr, + } + return io_wr, nil +} - target, err := GetIOWriterFromContext(ctx) +// Write copies the content of 'fh' to 'path'. It is assumed that either 'io_wr' was created using the +// NewIOWriterWithWriter method in which there is an explicit `io.Writer` target or that 'ctx' contains +// a valid `io.Writer` instance that has been assigned by the `SetIOWriterWithContext` method. +func (io_wr *IOWriter) Write(ctx context.Context, path string, fh io.ReadSeeker) (int64, error) { - if err != nil { - return 0, fmt.Errorf("Failed to get io.Writer instance from context, %w", err) + var wr io.Writer + + if io_wr.writer != nil { + wr = io_wr.writer + } else { + + target, err := GetIOWriterFromContext(ctx) + + if err != nil { + return 0, fmt.Errorf("Failed to get io.Writer instance from context, %w", err) + } + + wr = target } - return io.Copy(target, fh) + return io.Copy(wr, fh) } // WriterURI returns the final URI for path. -func (wr *IOWriter) WriterURI(ctx context.Context, path string) string { +func (io_wr *IOWriter) WriterURI(ctx context.Context, path string) string { return path } // Flush publish any outstanding data. -func (wr *IOWriter) Flush(ctx context.Context) error { +func (io_wr *IOWriter) Flush(ctx context.Context) error { return nil } // Close closes the underlying writer mechanism. -func (wr *IOWriter) Close(ctx context.Context) error { +func (io_wr *IOWriter) Close(ctx context.Context) error { return nil } // SetLogger assigns 'logger' to 'wr'. -func (wr *IOWriter) SetLogger(ctx context.Context, logger *log.Logger) error { +func (io_wr *IOWriter) SetLogger(ctx context.Context, logger *log.Logger) error { return nil } diff --git a/vendor/modules.txt b/vendor/modules.txt index 93d4265..b5a10b7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,5 +1,5 @@ -# github.com/aaronland/go-json-query v0.1.2 -## explicit; go 1.12 +# github.com/aaronland/go-json-query v0.1.3 +## explicit; go 1.18 github.com/aaronland/go-json-query # github.com/aaronland/go-roster v1.0.0 ## explicit; go 1.16 @@ -10,6 +10,12 @@ github.com/dhconnelly/rtreego # github.com/g8rswimmer/error-chain v1.0.0 ## explicit github.com/g8rswimmer/error-chain +# github.com/hashicorp/errwrap v1.0.0 +## explicit +github.com/hashicorp/errwrap +# github.com/hashicorp/go-multierror v1.1.1 +## explicit; go 1.13 +github.com/hashicorp/go-multierror # github.com/natefinch/atomic v1.0.1 ## explicit; go 1.12 github.com/natefinch/atomic @@ -38,7 +44,7 @@ github.com/sfomuseum/go-edtf/tests github.com/sfomuseum/go-flags/flagset github.com/sfomuseum/go-flags/lookup github.com/sfomuseum/go-flags/multi -# github.com/tidwall/gjson v1.14.3 +# github.com/tidwall/gjson v1.14.4 ## explicit; go 1.12 github.com/tidwall/gjson # github.com/tidwall/match v1.1.1 @@ -53,8 +59,8 @@ github.com/tidwall/sjson # github.com/whosonfirst/go-ioutil v1.0.2 ## explicit; go 1.16 github.com/whosonfirst/go-ioutil -# github.com/whosonfirst/go-reader v1.0.1 -## explicit; go 1.16 +# github.com/whosonfirst/go-reader v1.0.2 +## explicit; go 1.18 github.com/whosonfirst/go-reader # github.com/whosonfirst/go-sanitize v0.1.0 ## explicit; go 1.12 @@ -62,8 +68,8 @@ github.com/whosonfirst/go-sanitize # github.com/whosonfirst/go-whosonfirst-crawl v0.2.1 ## explicit; go 1.12 github.com/whosonfirst/go-whosonfirst-crawl -# github.com/whosonfirst/go-whosonfirst-feature v0.0.24 -## explicit; go 1.16 +# github.com/whosonfirst/go-whosonfirst-feature v0.0.25 +## explicit; go 1.18 github.com/whosonfirst/go-whosonfirst-feature/alt github.com/whosonfirst/go-whosonfirst-feature/geometry github.com/whosonfirst/go-whosonfirst-feature/properties @@ -74,34 +80,32 @@ github.com/whosonfirst/go-whosonfirst-flags/date github.com/whosonfirst/go-whosonfirst-flags/existential github.com/whosonfirst/go-whosonfirst-flags/geometry github.com/whosonfirst/go-whosonfirst-flags/placetypes -# github.com/whosonfirst/go-whosonfirst-iterate/v2 v2.3.0 -## explicit; go 1.16 +# github.com/whosonfirst/go-whosonfirst-iterate/v2 v2.3.1 +## explicit; go 1.18 github.com/whosonfirst/go-whosonfirst-iterate/v2/emitter github.com/whosonfirst/go-whosonfirst-iterate/v2/filters github.com/whosonfirst/go-whosonfirst-iterate/v2/iterator -# github.com/whosonfirst/go-whosonfirst-placetypes v0.3.0 -## explicit; go 1.12 +# github.com/whosonfirst/go-whosonfirst-placetypes v0.4.2 +## explicit; go 1.18 github.com/whosonfirst/go-whosonfirst-placetypes -github.com/whosonfirst/go-whosonfirst-placetypes/placetypes # github.com/whosonfirst/go-whosonfirst-sources v0.1.0 ## explicit; go 1.12 github.com/whosonfirst/go-whosonfirst-sources github.com/whosonfirst/go-whosonfirst-sources/sources -# github.com/whosonfirst/go-whosonfirst-spatial v0.4.0 +# github.com/whosonfirst/go-whosonfirst-spatial v0.5.4 ## explicit; go 1.18 github.com/whosonfirst/go-whosonfirst-spatial github.com/whosonfirst/go-whosonfirst-spatial/database github.com/whosonfirst/go-whosonfirst-spatial/filter github.com/whosonfirst/go-whosonfirst-spatial/flags github.com/whosonfirst/go-whosonfirst-spatial/geo -github.com/whosonfirst/go-whosonfirst-spatial/timer -# github.com/whosonfirst/go-whosonfirst-spr/v2 v2.2.1 -## explicit; go 1.16 +# github.com/whosonfirst/go-whosonfirst-spr/v2 v2.3.3 +## explicit; go 1.18 github.com/whosonfirst/go-whosonfirst-spr/v2 # github.com/whosonfirst/go-whosonfirst-uri v1.2.0 ## explicit; go 1.13 github.com/whosonfirst/go-whosonfirst-uri -# github.com/whosonfirst/go-writer/v3 v3.0.0 +# github.com/whosonfirst/go-writer/v3 v3.1.0 ## explicit; go 1.18 github.com/whosonfirst/go-writer/v3 # github.com/whosonfirst/walk v0.0.1