# HG changeset patch # User Sascha L. Teichmann # Date 1545041591 -3600 # Node ID 5e16d1fbe91f89ae89062ccba986aeeeb952eaf6 # Parent 4057b366db5f4f276b05c7ea3a513b649bec8a18 WFS Capabilities parser: Parse constraints, too. diff -r 4057b366db5f -r 5e16d1fbe91f cmd/wfs/main.go --- a/cmd/wfs/main.go Mon Dec 17 10:43:04 2018 +0100 +++ b/cmd/wfs/main.go Mon Dec 17 11:13:11 2018 +0100 @@ -44,19 +44,55 @@ fmt.Printf("title: %s\n", caps.ServiceIdentification.Title) fmt.Printf("type: %s\n", caps.ServiceIdentification.ServiceType) fmt.Printf("version: %s\n", caps.ServiceIdentification.ServiceTypeVersion) - for _, operation := range caps.OperationsMetadata.Operations { - fmt.Printf("\t%s\n", operation.Name) - if operation.DCP.HTTP.Get != nil { - fmt.Printf("\t\tGet: %s\n", operation.DCP.HTTP.Get.HRef) + if len(caps.OperationsMetadata.Operations) > 0 { + fmt.Println("operations:") + for _, operation := range caps.OperationsMetadata.Operations { + fmt.Printf("\t%s\n", operation.Name) + if operation.DCP.HTTP.Get != nil { + fmt.Printf("\t\tGet: %s\n", operation.DCP.HTTP.Get.HRef) + } + if operation.DCP.HTTP.Post != nil { + fmt.Printf("\t\tPost: %s\n", operation.DCP.HTTP.Post.HRef) + } + + if len(operation.Parameters) > 0 { + fmt.Println("\t\tparameters:") + for _, p := range operation.Parameters { + fmt.Printf("\t\t\tparameter: %s\n", p.Name) + for _, av := range p.AllowedValues.Values { + fmt.Printf("\t\t\t\t%s\n", av.Value) + } + } + } + if len(operation.Constraints) > 0 { + fmt.Println("\t\tconstraints:") + for _, c := range operation.Constraints { + fmt.Printf("\t\t\tname: %s\n", c.Name) + if c.DefaultValue != nil { + fmt.Printf("\t\t\t\tdefault: %s\n", c.DefaultValue.Value) + } + if len(c.AllowedValues.Values) > 0 { + fmt.Println("\t\t\tallowed values:") + for _, av := range c.AllowedValues.Values { + fmt.Printf("\t\t\t\t%s", av.Value) + } + } + } + } } - if operation.DCP.HTTP.Post != nil { - fmt.Printf("\t\tPost: %s\n", operation.DCP.HTTP.Post.HRef) - } - - for _, p := range operation.Parameters { - fmt.Printf("\t\tparameter: %s\n", p.Name) - for _, av := range p.AllowedValues.AllowedValues { - fmt.Printf("\t\t\t%s\n", av.Value) + } + if len(caps.OperationsMetadata.Constraints) > 0 { + fmt.Println("constraints:") + for _, c := range caps.OperationsMetadata.Constraints { + fmt.Printf("\tname: %s\n", c.Name) + if c.DefaultValue != nil { + fmt.Printf("\t\tdefault: %s\n", c.DefaultValue.Value) + } + if len(c.AllowedValues.Values) > 0 { + fmt.Println("\tallowed values:") + for _, av := range c.AllowedValues.Values { + fmt.Printf("\t\t%s\n", av.Value) + } } } } diff -r 4057b366db5f -r 5e16d1fbe91f pkg/wfs/capabilities.go --- a/pkg/wfs/capabilities.go Mon Dec 17 10:43:04 2018 +0100 +++ b/pkg/wfs/capabilities.go Mon Dec 17 11:13:11 2018 +0100 @@ -49,14 +49,14 @@ HTTP HTTP `xml:"HTTP"` } -type AllowedValue struct { +type Value struct { XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 Value"` Value string `xml:",cdata"` } type AllowedValues struct { - XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 AllowedValues"` - AllowedValues []AllowedValue `xml:"Value"` + XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 AllowedValues"` + Values []Value `xml:"Value"` } type Parameter struct { @@ -65,16 +65,30 @@ AllowedValues AllowedValues `xml:"AllowedValues"` } +type DefaultValue struct { + XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 DefaultValue"` + Value string `xml:",cdata"` +} + +type Constraint struct { + XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 Constraint"` + Name string `xml:"name,attr"` + AllowedValues AllowedValues `xml:"AllowedValues"` + DefaultValue *DefaultValue `xml:"DefaultValue"` +} + type Operation struct { - XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 Operation"` - Name string `xml:"name,attr"` - DCP DCP `xml:"DCP"` - Parameters []*Parameter `xml:"Parameter"` + XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 Operation"` + Name string `xml:"name,attr"` + DCP DCP `xml:"DCP"` + Parameters []*Parameter `xml:"Parameter"` + Constraints []*Constraint `xml:"Constraint"` } type OperationsMetadata struct { - XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 OperationsMetadata"` - Operations []*Operation `xml:"http://www.opengis.net/ows/1.1 Operation"` + XMLName xml.Name `xml:"http://www.opengis.net/ows/1.1 OperationsMetadata"` + Operations []*Operation `xml:"Operation"` + Constraints []*Constraint `xml:"Constraint"` } type Capabilities struct {