github.com/go-spatial/go-wfs@v0.1.4-0.20190401000911-c9fba2bb5188/wfs3/collection_meta_data.go (about) 1 /////////////////////////////////////////////////////////////////////////////// 2 // 3 // The MIT License (MIT) 4 // Copyright (c) 2018 Jivan Amara 5 // 6 // Permission is hereby granted, free of charge, to any person obtaining a copy 7 // of this software and associated documentation files (the "Software"), to 8 // deal in the Software without restriction, including without limitation the 9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 // sell copies of the Software, and to permit persons to whom the Software is 11 // furnished to do so, subject to the following conditions: 12 // 13 // The above copyright notice and this permission notice shall be included in 14 // all copies or substantial portions of the Software. 15 // 16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 20 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22 // USE OR OTHER DEALINGS IN THE SOFTWARE. 23 // 24 /////////////////////////////////////////////////////////////////////////////// 25 26 // jivan project collection_meta_data.go 27 28 package wfs3 29 30 import ( 31 "fmt" 32 "hash/fnv" 33 "log" 34 35 "github.com/go-spatial/jivan/data_provider" 36 ) 37 38 func CollectionsMetaData(p *data_provider.Provider, serveAddress string, checkOnly bool) (content *CollectionsInfo, contentId string, err error) { 39 // TODO: This calculation of contentId assumes an unchanging data set. 40 // When a changing data set is needed this will have to be updated, hopefully after data providers can tell us 41 // something about updates. 42 hasher := fnv.New64() 43 hasher.Write([]byte(fmt.Sprintf("%v", serveAddress))) 44 contentId = fmt.Sprintf("%x", hasher.Sum64()) 45 if checkOnly { 46 return nil, contentId, nil 47 } 48 49 cNames, err := p.CollectionNames() 50 if err != nil { 51 // TODO: Log error 52 return nil, "", err 53 } 54 55 csInfo := CollectionsInfo{Links: []*Link{}, Collections: []*CollectionInfo{}} 56 for _, cn := range cNames { 57 cInfo, _, err := CollectionMetaData(cn, p, serveAddress, checkOnly) 58 if err != nil { 59 return nil, "", err 60 } 61 csInfo.Collections = append(csInfo.Collections, cInfo) 62 } 63 64 return &csInfo, contentId, nil 65 } 66 67 func CollectionMetaData(name string, p *data_provider.Provider, serveAddress string, checkOnly bool) (content *CollectionInfo, contentId string, err error) { 68 // TODO: This calculation of contentId assumes an unchanging data set. 69 // When a changing data set is needed this will have to be updated, hopefully after data providers can tell us 70 // something about updates. 71 hasher := fnv.New64() 72 hasher.Write([]byte(fmt.Sprintf("%v%v", serveAddress, name))) 73 contentId = fmt.Sprintf("%x", hasher.Sum64()) 74 if checkOnly { 75 return nil, contentId, nil 76 } 77 78 cNames, err := p.CollectionNames() 79 if err != nil { 80 log.Printf("problem getting collection names: %v", err) 81 return nil, "", err 82 } 83 84 validName := false 85 for _, cName := range cNames { 86 if name == cName { 87 validName = true 88 break 89 } 90 } 91 if !validName { 92 return nil, "", fmt.Errorf("Invalid collection name: %v", name) 93 } 94 95 cInfo := CollectionInfo{Name: name, Title: name, Links: []*Link{}} 96 97 return &cInfo, contentId, nil 98 }