Skip to content

Commit 860f6d7

Browse files
authored
Merge pull request #39 from PDOK/1.x-refactor-anonymous-structs
1.x refactor anonymous structs
2 parents 1276aaa + 1d17d84 commit 860f6d7

File tree

8 files changed

+209
-135
lines changed

8 files changed

+209
-135
lines changed

pkg/wcs201/getcapabilities_response.go

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -60,49 +60,70 @@ type Namespaces struct {
6060

6161
// ServiceIdentification struct should only be fill by the "template" configuration wcs201.yaml
6262
type ServiceIdentification struct {
63-
Title string `xml:"ows:Title" yaml:"title"`
64-
Abstract string `xml:"ows:Abstract" yaml:"abstract"`
65-
Keywords *wsc200.Keywords `xml:"ows:Keywords" yaml:"keywords"`
66-
ServiceType struct {
67-
Text string `xml:",chardata" yaml:"text"`
68-
CodeSpace string `xml:"codeSpace,attr" yaml:"codeSpace"`
69-
} `xml:"ows:ServiceType" yaml:"serviceType"`
70-
ServiceTypeVersion []string `xml:"ows:ServiceTypeVersion" yaml:"serviceTypeVersion"`
71-
Profile []string `xml:"ows:Profile" yaml:"profile"`
72-
Fees string `xml:"ows:Fees" yaml:"fees"`
73-
AccessConstraints string `xml:"ows:AccessConstraints" yaml:"accessConstraints"`
63+
Title string `xml:"ows:Title" yaml:"title"`
64+
Abstract string `xml:"ows:Abstract" yaml:"abstract"`
65+
Keywords *wsc200.Keywords `xml:"ows:Keywords" yaml:"keywords"`
66+
ServiceType ServiceType `xml:"ows:ServiceType" yaml:"serviceType"`
67+
ServiceTypeVersion []string `xml:"ows:ServiceTypeVersion" yaml:"serviceTypeVersion"`
68+
Profile []string `xml:"ows:Profile" yaml:"profile"`
69+
Fees string `xml:"ows:Fees" yaml:"fees"`
70+
AccessConstraints string `xml:"ows:AccessConstraints" yaml:"accessConstraints"`
71+
}
72+
73+
// ServiceType struct containing the service type
74+
type ServiceType struct {
75+
Text string `xml:",chardata" yaml:"text"`
76+
CodeSpace string `xml:"codeSpace,attr" yaml:"codeSpace"`
7477
}
7578

7679
// ServiceProvider struct containing the provider/organization information should only be fill by the "template" configuration wcs201.yaml
7780
type ServiceProvider struct {
78-
ProviderName string `xml:"ows:ProviderName" yaml:"providerName"`
79-
ProviderSite struct {
80-
Type string `xml:"xlink:type,attr" yaml:"type"`
81-
Href string `xml:"xlink:href,attr" yaml:"href"`
82-
} `xml:"ows:ProviderSite" yaml:"providerSite"`
83-
ServiceContact struct {
84-
IndividualName string `xml:"ows:IndividualName" yaml:"individualName"`
85-
PositionName string `xml:"ows:PositionName" yaml:"positionName"`
86-
ContactInfo struct {
87-
Phone struct {
88-
Voice string `xml:"ows:Voice" yaml:"voice"`
89-
Facsimile string `xml:"ows:Facsimile" yaml:"facsimile"`
90-
} `xml:"ows:Phone" yaml:"phone"`
91-
Address struct {
92-
DeliveryPoint string `xml:"ows:DeliveryPoint" yaml:"deliveryPoint"`
93-
City string `xml:"ows:City" yaml:"city"`
94-
AdministrativeArea string `xml:"ows:AdministrativeArea" yaml:"administrativeArea"`
95-
PostalCode string `xml:"ows:PostalCode" yaml:"postalCode"`
96-
Country string `xml:"ows:Country" yaml:"country"`
97-
ElectronicMailAddress string `xml:"ows:ElectronicMailAddress" yaml:"electronicMailAddress"`
98-
} `xml:"ows:Address" yaml:"address"`
99-
OnlineResource *struct {
100-
Type string `xml:"xlink:type,attr,omitempty" yaml:"type"`
101-
Href string `xml:"xlink:href,attr,omitempty" yaml:"href"`
102-
} `xml:"ows:OnlineResource,omitempty" yaml:"onlineResource"`
103-
HoursOfService string `xml:"ows:HoursOfService,omitempty" yaml:"hoursOfService"`
104-
ContactInstructions string `xml:"ows:ContactInstructions,omitempty" yaml:"contactInstructions"`
105-
} `xml:"ows:ContactInfo" yaml:"contactInfo"`
106-
Role string `xml:"ows:Role,omitempty" yaml:"role"`
107-
} `xml:"ows:ServiceContact" yaml:"serviceContact"`
81+
ProviderName string `xml:"ows:ProviderName" yaml:"providerName"`
82+
ProviderSite `xml:"ows:ProviderSite" yaml:"providerSite"`
83+
ServiceContact ServiceContact `xml:"ows:ServiceContact" yaml:"serviceContact"`
84+
}
85+
86+
// ProviderSite struct containing the website of the provider/organization
87+
type ProviderSite struct {
88+
Type string `xml:"xlink:type,attr" yaml:"type"`
89+
Href string `xml:"xlink:href,attr" yaml:"href"`
90+
}
91+
92+
// ServiceContact struct containing information for the person to contact
93+
type ServiceContact struct {
94+
IndividualName string `xml:"ows:IndividualName" yaml:"individualName"`
95+
PositionName string `xml:"ows:PositionName" yaml:"positionName"`
96+
ContactInfo ContactInfo `xml:"ows:ContactInfo" yaml:"contactInfo"`
97+
Role string `xml:"ows:Role,omitempty" yaml:"role"`
98+
}
99+
100+
// ContactInfo struct containing the contact information for the service
101+
type ContactInfo struct {
102+
Phone Phone `xml:"ows:Phone" yaml:"phone"`
103+
Address Address `xml:"ows:Address" yaml:"address"`
104+
OnlineResource *OnlineResource `xml:"ows:OnlineResource,omitempty" yaml:"onlineResource"`
105+
HoursOfService string `xml:"ows:HoursOfService,omitempty" yaml:"hoursOfService"`
106+
ContactInstructions string `xml:"ows:ContactInstructions,omitempty" yaml:"contactInstructions"`
107+
}
108+
109+
// Phone struct containing the contact telephone or fax number
110+
type Phone struct {
111+
Voice string `xml:"ows:Voice" yaml:"voice"`
112+
Facsimile string `xml:"ows:Facsimile" yaml:"facsimile"`
113+
}
114+
115+
// Address struct containing the address for the contact supplying the service
116+
type Address struct {
117+
DeliveryPoint string `xml:"ows:DeliveryPoint" yaml:"deliveryPoint"`
118+
City string `xml:"ows:City" yaml:"city"`
119+
AdministrativeArea string `xml:"ows:AdministrativeArea" yaml:"administrativeArea"`
120+
PostalCode string `xml:"ows:PostalCode" yaml:"postalCode"`
121+
Country string `xml:"ows:Country" yaml:"country"`
122+
ElectronicMailAddress string `xml:"ows:ElectronicMailAddress" yaml:"electronicMailAddress"`
123+
}
124+
125+
// OnlineResource struct containing the top-level web address of a service or service provider
126+
type OnlineResource *struct {
127+
Type string `xml:"xlink:type,attr,omitempty" yaml:"type"`
128+
Href string `xml:"xlink:href,attr,omitempty" yaml:"href"`
108129
}

pkg/wfs200/capabilities.go

Lines changed: 14 additions & 14 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

@@ -146,9 +146,9 @@ type FeatureType struct {
146146
Abstract string `xml:"Abstract" yaml:"abstract"`
147147
Keywords *[]wsc110.Keywords `xml:"ows:Keywords" yaml:"keywords"`
148148
DefaultCRS *CRS `xml:"DefaultCRS" yaml:"defaultCrs"`
149-
OtherCRS *[]CRS `xml:"OtherCRS" yaml:"otherCrs"`
150-
OutputFormats OutputFormats `xml:"OutputFormats" yaml:"outputFormats"`
151-
WGS84BoundingBox *wsc110.WGS84BoundingBox `xml:"ows:WGS84BoundingBox" yaml:"wgs84BoundingBox"`
149+
OtherCRS []*CRS `xml:"OtherCRS" yaml:"otherCrs"`
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: 67 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func (gc GetCapabilitiesResponse) ToXML() []byte {
3838

3939
// GetCapabilitiesResponse base struct
4040
type GetCapabilitiesResponse struct {
41-
XMLName xml.Name `xml:"WFS_Capabilities"`
42-
Namespaces `yaml:"namespaces"`
41+
XMLName xml.Name `xml:"WFS_Capabilities" yaml:"-"`
42+
*Namespaces `yaml:"namespaces,omitempty"`
4343
ServiceIdentification ServiceIdentification `xml:"ows:ServiceIdentification" yaml:"serviceIdentification"`
4444
ServiceProvider ServiceProvider `xml:"ows:ServiceProvider" yaml:"serviceProvider"`
4545
Capabilities `yaml:"capabilities"`
@@ -60,53 +60,74 @@ type Namespaces struct {
6060
SchemaLocation string `xml:"xsi:schemaLocation,attr" yaml:"schemaLocation"`
6161
}
6262

63-
// ServiceIdentification struct should only be fill by the "template" configuration wfs200.yaml
63+
// ServiceIdentification struct should only be filled by the "template" configuration wfs200.yaml
6464
type ServiceIdentification struct {
65-
XMLName xml.Name `xml:"ows:ServiceIdentification"`
66-
Title string `xml:"ows:Title" yaml:"title"`
67-
Abstract string `xml:"ows:Abstract" yaml:"abstract"`
68-
Keywords *wsc110.Keywords `xml:"ows:Keywords" yaml:"keywords"`
69-
ServiceType struct {
70-
Text string `xml:",chardata" yaml:"text"`
71-
CodeSpace string `xml:"codeSpace,attr" yaml:"codeSpace"`
72-
} `xml:"ows:ServiceType" yaml:"serviceType"`
73-
ServiceTypeVersion string `xml:"ows:ServiceTypeVersion" yaml:"serviceTypeVersion"`
74-
Fees string `xml:"ows:Fees" yaml:"fees"`
75-
AccessConstraints string `xml:"ows:AccessConstraints" yaml:"accessConstraints"`
65+
XMLName xml.Name `xml:"ows:ServiceIdentification" yaml:"-"`
66+
Title string `xml:"ows:Title" yaml:"title"`
67+
Abstract string `xml:"ows:Abstract" yaml:"abstract"`
68+
Keywords *wsc110.Keywords `xml:"ows:Keywords" yaml:"keywords"`
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"`
72+
AccessConstraints string `xml:"ows:AccessConstraints" yaml:"accessConstraints"`
73+
}
74+
75+
// ServiceType struct containing the service type
76+
type ServiceType struct {
77+
Text string `xml:",chardata" yaml:"text"`
78+
CodeSpace string `xml:"codeSpace,attr" yaml:"codeSpace"`
7679
}
7780

7881
// ServiceProvider struct containing the provider/organization information should only be fill by the "template" configuration wfs200.yaml
7982
type ServiceProvider struct {
80-
XMLName xml.Name `xml:"ows:ServiceProvider"`
81-
ProviderName string `xml:"ows:ProviderName" yaml:"providerName"`
82-
ProviderSite struct {
83-
Type string `xml:"xlink:type,attr" yaml:"type"`
84-
Href string `xml:"xlink:href,attr" yaml:"href"`
85-
} `xml:"ows:ProviderSite" yaml:"providerSite"`
86-
ServiceContact struct {
87-
IndividualName string `xml:"ows:IndividualName" yaml:"individualName"`
88-
PositionName string `xml:"ows:PositionName" yaml:"positionName"`
89-
ContactInfo struct {
90-
Text string `xml:",chardata"`
91-
Phone struct {
92-
Voice string `xml:"ows:Voice" yaml:"voice"`
93-
Facsimile string `xml:"ows:Facsimile" yaml:"facsimile"`
94-
} `xml:"ows:Phone" yaml:"phone"`
95-
Address struct {
96-
DeliveryPoint string `xml:"ows:DeliveryPoint" yaml:"deliveryPoint"`
97-
City string `xml:"ows:City" yaml:"city"`
98-
AdministrativeArea string `xml:"ows:AdministrativeArea" yaml:"administrativeArea"`
99-
PostalCode string `xml:"ows:PostalCode" yaml:"postalCode"`
100-
Country string `xml:"ows:Country" yaml:"country"`
101-
ElectronicMailAddress string `xml:"ows:ElectronicMailAddress" yaml:"electronicMailAddress"`
102-
} `xml:"ows:Address" yaml:"address"`
103-
OnlineResource struct {
104-
Type string `xml:"xlink:type,attr" yaml:"type"`
105-
Href string `xml:"xlink:href,attr" yaml:"href"`
106-
} `xml:"ows:OnlineResource" yaml:"onlineResource"`
107-
HoursOfService string `xml:"ows:HoursOfService" yaml:"hoursOfService"`
108-
ContactInstructions string `xml:"ows:ContactInstructions" yaml:"contactInstructions"`
109-
} `xml:"ows:ContactInfo" yaml:"contactInfo"`
110-
Role string `xml:"ows:Role" yaml:"role"`
111-
} `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"`
87+
}
88+
89+
// ProviderSite struct containing the website of the provider/organization
90+
type ProviderSite struct {
91+
Type string `xml:"xlink:type,attr" yaml:"type"`
92+
Href string `xml:"xlink:href,attr" yaml:"href"`
93+
}
94+
95+
// ServiceContact struct containing information for the person to contact
96+
type ServiceContact struct {
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"`
101+
}
102+
103+
// ContactInfo struct containing the contact information for the service
104+
type ContactInfo struct {
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"`
111+
}
112+
113+
// Phone struct containing the contact telephone or fax number
114+
type Phone struct {
115+
Voice *string `xml:"ows:Voice" yaml:"voice,omitempty"`
116+
Facsimile *string `xml:"ows:Facsimile" yaml:"facsimile,omitempty"`
117+
}
118+
119+
// Address struct containing the address for the contact supplying the service
120+
type Address struct {
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"`
127+
}
128+
129+
// OnlineResource struct containing the top-level web address of a service or service provider
130+
type OnlineResource struct {
131+
Type *string `xml:"xlink:type,attr" yaml:"type,omitempty"`
132+
Href *string `xml:"xlink:href,attr" yaml:"href,omitempty"`
112133
}

0 commit comments

Comments
 (0)