Skip to content

Commit a70d7e8

Browse files
committed
YAML tags for marshalling WFS capabilities
1 parent 985788a commit a70d7e8

File tree

6 files changed

+71
-44
lines changed

6 files changed

+71
-44
lines changed

pkg/wfs200/capabilities.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ func (c *Capabilities) ParseYAML(doc []byte) error {
1818

1919
// Capabilities struct
2020
type Capabilities struct {
21-
OperationsMetadata OperationsMetadata `xml:"ows:OperationsMetadata" yaml:"operationsMetadata"`
22-
FeatureTypeList FeatureTypeList `xml:"FeatureTypeList" yaml:"featureTypeList"`
23-
FilterCapabilities FilterCapabilities `xml:"fes:Filter_Capabilities" yaml:"filterCapabilities"`
21+
OperationsMetadata *OperationsMetadata `xml:"ows:OperationsMetadata" yaml:"operationsMetadata,omitempty"`
22+
FeatureTypeList FeatureTypeList `xml:"FeatureTypeList" yaml:"featureTypeList"`
23+
FilterCapabilities *FilterCapabilities `xml:"fes:Filter_Capabilities" yaml:"filterCapabilities,omitempty"`
2424
}
2525

2626
// Method in separated struct so to use it as a Pointer
@@ -31,11 +31,11 @@ type Method struct {
3131

3232
// OperationsMetadata struct for the WFS 2.0.0
3333
type OperationsMetadata struct {
34-
XMLName xml.Name `xml:"ows:OperationsMetadata" yaml:"operationsMetadata"`
35-
Operation []Operation `xml:"ows:Operation" yaml:"operation"`
36-
Parameter Parameter `xml:"ows:Parameter" yaml:"parameter"`
37-
Constraint []Constraint `xml:"ows:Constraint" yaml:"constraint"`
38-
ExtendedCapabilities *ExtendedCapabilities `xml:"ows:ExtendedCapabilities" yaml:"extendedCapabilities"`
34+
XMLName xml.Name `xml:"ows:OperationsMetadata" yaml:"-"`
35+
Operation []Operation `xml:"ows:Operation" yaml:"operation,omitempty"`
36+
Parameter *Parameter `xml:"ows:Parameter" yaml:"parameter,omitempty"`
37+
Constraint []Constraint `xml:"ows:Constraint" yaml:"constraint,omitempty"`
38+
ExtendedCapabilities *ExtendedCapabilities `xml:"ows:ExtendedCapabilities" yaml:"extendedCapabilities,omitempty"`
3939
}
4040

4141
// Parameter struct for the WFS 2.0.0
@@ -104,7 +104,7 @@ type ExtendedCapabilities struct {
104104

105105
// NestedExtendedCapabilities struct for the WFS 2.0.0
106106
type NestedExtendedCapabilities struct {
107-
Text string `xml:",chardata" yaml:"text"`
107+
Text *string `xml:",chardata" yaml:"text,omitempty"`
108108
MetadataURL MetadataURL `xml:"inspire_common:MetadataUrl" yaml:"metadataUrl"`
109109
SupportedLanguages SupportedLanguages `xml:"inspire_common:SupportedLanguages" yaml:"supportedLanguages"`
110110
ResponseLanguage Language `xml:"inspire_common:ResponseLanguage" yaml:"responseLanguage"`
@@ -120,7 +120,7 @@ type MetadataURL struct {
120120
// SupportedLanguages struct for the WFS 2.0.0
121121
type SupportedLanguages struct {
122122
DefaultLanguage Language `xml:"inspire_common:DefaultLanguage" yaml:"defaultLanguage"`
123-
SupportedLanguage *[]Language `xml:"inspire_common:SupportedLanguage" yaml:"supportedLanguage"`
123+
SupportedLanguage *[]Language `xml:"inspire_common:SupportedLanguage" yaml:"supportedLanguage,omitempty"`
124124
}
125125

126126
// Language struct for the WFS 2.0.0
@@ -135,7 +135,7 @@ type SpatialDataSetIdentifier struct {
135135

136136
// FeatureTypeList struct for the WFS 2.0.0
137137
type FeatureTypeList struct {
138-
XMLName xml.Name `xml:"FeatureTypeList" yaml:"featureTypeList"`
138+
XMLName xml.Name `xml:"FeatureTypeList" yaml:"-"`
139139
FeatureType []FeatureType `xml:"FeatureType" yaml:"featureType"`
140140
}
141141

@@ -147,8 +147,8 @@ type FeatureType struct {
147147
Keywords *[]wsc110.Keywords `xml:"ows:Keywords" yaml:"keywords"`
148148
DefaultCRS *CRS `xml:"DefaultCRS" yaml:"defaultCrs"`
149149
OtherCRS *[]CRS `xml:"OtherCRS" yaml:"otherCrs"`
150-
OutputFormats OutputFormats `xml:"OutputFormats" yaml:"outputFormats"`
151-
WGS84BoundingBox *wsc110.WGS84BoundingBox `xml:"ows:WGS84BoundingBox" yaml:"wgs84BoundingBox"`
150+
OutputFormats *OutputFormats `xml:"OutputFormats" yaml:"outputFormats,omitempty"`
151+
WGS84BoundingBox *wsc110.WGS84BoundingBox `xml:"ows:WGS84BoundingBox" yaml:"wgs84BoundingBox,omitempty"`
152152
MetadataURL MetadataHref `xml:"MetadataURL" yaml:"metadataUrl"`
153153
}
154154

pkg/wfs200/crs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strconv"
66
)
77

8-
//
98
const (
109
codeSpace = `urn:ogc:def:crs:EPSG:`
1110
)

pkg/wfs200/crs_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,25 @@ othercrs:
5858
}
5959
}
6060
}
61+
62+
func TestMarshalYAMLCrs(t *testing.T) {
63+
var stringYAML = `urn:ogc:def:crs:EPSG::4326
64+
`
65+
tests := []struct {
66+
CRS *CRS
67+
expectedYAML string
68+
}{
69+
0: {CRS: &CRS{Code: 4326, Namespace: codeSpace}, expectedYAML: stringYAML},
70+
}
71+
for k, test := range tests {
72+
yamlCRS, err := yaml.Marshal(test.CRS)
73+
if err != nil {
74+
t.Errorf("test: %d, yaml.Marshal failed with '%s'\n", k, err)
75+
} else {
76+
stringCRS := string(yamlCRS)
77+
if stringCRS != test.expectedYAML {
78+
t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedYAML, stringCRS)
79+
}
80+
}
81+
}
82+
}

pkg/wfs200/crs_yaml.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package wfs200
22

3+
import "strconv"
4+
35
// UnmarshalYAML CRS
46
func (c *CRS) UnmarshalYAML(unmarshal func(interface{}) error) error {
57
var s string
@@ -14,3 +16,7 @@ func (c *CRS) UnmarshalYAML(unmarshal func(interface{}) error) error {
1416

1517
return nil
1618
}
19+
20+
func (c *CRS) MarshalYAML() (interface{}, error) {
21+
return codeSpace + ":" + strconv.Itoa(c.Code), nil
22+
}

pkg/wfs200/getcapabilities_response.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (gc GetCapabilitiesResponse) ToXML() []byte {
3838

3939
// GetCapabilitiesResponse base struct
4040
type GetCapabilitiesResponse struct {
41-
XMLName xml.Name `xml:"WFS_Capabilities"`
41+
XMLName xml.Name `xml:"WFS_Capabilities" yaml:"-"`
4242
Namespaces `yaml:"namespaces"`
4343
ServiceIdentification ServiceIdentification `xml:"ows:ServiceIdentification" yaml:"serviceIdentification"`
4444
ServiceProvider ServiceProvider `xml:"ows:ServiceProvider" yaml:"serviceProvider"`
@@ -62,13 +62,13 @@ type Namespaces struct {
6262

6363
// ServiceIdentification struct should only be filled by the "template" configuration wfs200.yaml
6464
type ServiceIdentification struct {
65-
XMLName xml.Name `xml:"ows:ServiceIdentification"`
65+
XMLName xml.Name `xml:"ows:ServiceIdentification" yaml:"-"`
6666
Title string `xml:"ows:Title" yaml:"title"`
6767
Abstract string `xml:"ows:Abstract" yaml:"abstract"`
6868
Keywords *wsc110.Keywords `xml:"ows:Keywords" yaml:"keywords"`
69-
ServiceType ServiceType `xml:"ows:ServiceType" yaml:"serviceType"`
70-
ServiceTypeVersion string `xml:"ows:ServiceTypeVersion" yaml:"serviceTypeVersion"`
71-
Fees string `xml:"ows:Fees" yaml:"fees"`
69+
ServiceType *ServiceType `xml:"ows:ServiceType" yaml:"serviceType,omitempty"`
70+
ServiceTypeVersion *string `xml:"ows:ServiceTypeVersion" yaml:"serviceTypeVersion,omitempty"`
71+
Fees *string `xml:"ows:Fees" yaml:"fees,omitempty"`
7272
AccessConstraints string `xml:"ows:AccessConstraints" yaml:"accessConstraints"`
7373
}
7474

@@ -80,10 +80,10 @@ type ServiceType struct {
8080

8181
// ServiceProvider struct containing the provider/organization information should only be fill by the "template" configuration wfs200.yaml
8282
type ServiceProvider struct {
83-
XMLName xml.Name `xml:"ows:ServiceProvider"`
84-
ProviderName string `xml:"ows:ProviderName" yaml:"providerName"`
85-
ProviderSite ProviderSite `xml:"ows:ProviderSite" yaml:"providerSite"`
86-
ServiceContact ServiceContact `xml:"ows:ServiceContact" yaml:"serviceContact"`
83+
XMLName xml.Name `xml:"ows:ServiceProvider" yaml:"-"`
84+
ProviderName *string `xml:"ows:ProviderName" yaml:"providerName,omitempty"`
85+
ProviderSite *ProviderSite `xml:"ows:ProviderSite" yaml:"providerSite,omitempty"`
86+
ServiceContact *ServiceContact `xml:"ows:ServiceContact" yaml:"serviceContact,omitempty"`
8787
}
8888

8989
// ProviderSite struct containing the website of the provider/organization
@@ -94,40 +94,40 @@ type ProviderSite struct {
9494

9595
// ServiceContact struct containing information for the person to contact
9696
type ServiceContact struct {
97-
IndividualName string `xml:"ows:IndividualName" yaml:"individualName"`
98-
PositionName string `xml:"ows:PositionName" yaml:"positionName"`
99-
ContactInfo ContactInfo `xml:"ows:ContactInfo" yaml:"contactInfo"`
100-
Role string `xml:"ows:Role" yaml:"role"`
97+
IndividualName *string `xml:"ows:IndividualName" yaml:"individualName,omitempty"`
98+
PositionName *string `xml:"ows:PositionName" yaml:"positionName,omitempty"`
99+
ContactInfo *ContactInfo `xml:"ows:ContactInfo" yaml:"contactInfo,omitempty"`
100+
Role *string `xml:"ows:Role" yaml:"role,omitempty"`
101101
}
102102

103103
// ContactInfo struct containing the contact information for the service
104104
type ContactInfo struct {
105-
Text string `xml:",chardata"`
106-
Phone Phone `xml:"ows:Phone" yaml:"phone"`
107-
Address Address `xml:"ows:Address" yaml:"address"`
108-
OnlineResource OnlineResource `xml:"ows:OnlineResource" yaml:"onlineResource"`
109-
HoursOfService string `xml:"ows:HoursOfService" yaml:"hoursOfService"`
110-
ContactInstructions string `xml:"ows:ContactInstructions" yaml:"contactInstructions"`
105+
Text *string `xml:",chardata" yaml:"text,omitempty"`
106+
Phone *Phone `xml:"ows:Phone" yaml:"phone,omitempty"`
107+
Address *Address `xml:"ows:Address" yaml:"address,omitempty"`
108+
OnlineResource *OnlineResource `xml:"ows:OnlineResource" yaml:"onlineResource,omitempty"`
109+
HoursOfService *string `xml:"ows:HoursOfService" yaml:"hoursOfService,omitempty"`
110+
ContactInstructions *string `xml:"ows:ContactInstructions" yaml:"contactInstructions,omitempty"`
111111
}
112112

113113
// Phone struct containing the contact telephone or fax number
114114
type Phone struct {
115-
Voice string `xml:"ows:Voice" yaml:"voice"`
116-
Facsimile string `xml:"ows:Facsimile" yaml:"facsimile"`
115+
Voice *string `xml:"ows:Voice" yaml:"voice"`
116+
Facsimile *string `xml:"ows:Facsimile" yaml:"facsimile,omitempty"`
117117
}
118118

119119
// Address struct containing the address for the contact supplying the service
120120
type Address struct {
121-
DeliveryPoint string `xml:"ows:DeliveryPoint" yaml:"deliveryPoint"`
122-
City string `xml:"ows:City" yaml:"city"`
123-
AdministrativeArea string `xml:"ows:AdministrativeArea" yaml:"administrativeArea"`
124-
PostalCode string `xml:"ows:PostalCode" yaml:"postalCode"`
125-
Country string `xml:"ows:Country" yaml:"country"`
126-
ElectronicMailAddress string `xml:"ows:ElectronicMailAddress" yaml:"electronicMailAddress"`
121+
DeliveryPoint *string `xml:"ows:DeliveryPoint" yaml:"deliveryPoint,omitempty"`
122+
City *string `xml:"ows:City" yaml:"city,omitempty"`
123+
AdministrativeArea *string `xml:"ows:AdministrativeArea" yaml:"administrativeArea,omitempty"`
124+
PostalCode *string `xml:"ows:PostalCode" yaml:"postalCode,omitempty"`
125+
Country *string `xml:"ows:Country" yaml:"country,omitempty"`
126+
ElectronicMailAddress *string `xml:"ows:ElectronicMailAddress" yaml:"electronicMailAddress,omitempty"`
127127
}
128128

129129
// OnlineResource struct containing the top-level web address of a service or service provider
130130
type OnlineResource struct {
131-
Type string `xml:"xlink:type,attr" yaml:"type"`
132-
Href string `xml:"xlink:href,attr" yaml:"href"`
131+
Type *string `xml:"xlink:type,attr" yaml:"type,omitempty"`
132+
Href *string `xml:"xlink:href,attr" yaml:"href,omitempty"`
133133
}

pkg/wsc110/keywords.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ type Keywords struct {
66
Type *struct {
77
Text string `xml:",chardata" yaml:"text"`
88
CodeSpace *string `xml:"codeSpace,attr,omitempty" yaml:"codeSpace"`
9-
} `xml:"ows:Type" yaml:"type"`
9+
} `xml:"ows:Type" yaml:"type,omitempty"`
1010
}

0 commit comments

Comments
 (0)