diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index f4df9e6..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Lint - -on: - push: - pull_request: - -jobs: - lint: - name: Run on Ubuntu - runs-on: ubuntu-latest - steps: - - name: Clone the code - uses: actions/checkout@v4 - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod - - - name: Run linter - uses: golangci/golangci-lint-action@v9 - with: - version: v2.9.0 diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index 9aca882..0000000 --- a/.golangci.yml +++ /dev/null @@ -1,129 +0,0 @@ -version: "2" -run: - timeout: 5m - modules-download-mode: readonly - tests: true - -linters: - default: none - enable: - - asasalint - - asciicheck - - bidichk - - bodyclose - - copyloopvar - - cyclop - - dogsled - - dupl - - durationcheck - - errcheck - - errname - - errorlint - - exhaustive - - exptostd - - fatcontext - - forbidigo - - funlen - - gocheckcompilerdirectives - - goconst - - gocritic - - gomoddirectives - - gomodguard - - goprintffuncname - - gosec - - govet - - ineffassign - - loggercheck - - makezero - - mirror - - misspell - - nakedret - - nestif - - nilerr - - nolintlint - - nosprintfhostport - - perfsprint - - predeclared - - promlinter - - reassign - - revive - - rowserrcheck - - sloglint - - sqlclosecheck -# - staticcheck - - tagliatelle - - testableexamples - - tparallel - - unconvert - - unparam - - unused - - usestdlibvars - - usetesting - - wastedassign # finds wasted assignment statements - settings: - revive: - rules: - # default rules - - name: blank-imports - - name: context-as-argument - - name: context-keys-type - - name: dot-imports - - name: empty-block - - name: error-naming - - name: error-return - - name: error-strings - - name: errorf - - name: increment-decrement - - name: indent-error-flow - - name: range - - name: receiver-naming - - name: redefines-builtin-id - - name: superfluous-else - - name: time-naming - - name: unexported-return - - name: unreachable-code - - name: unused-parameter - - name: var-declaration - # enabled or tweaked by us - - name: use-any - cyclop: - max-complexity: 15 - depguard: - rules: - main: - deny: - - pkg: github.com/pkg/errors - desc: Should be replaced by standard lib errors package - forbidigo: - forbid: - - pattern: http\.NotFound.* - - pattern: http\.Error.* - funlen: - lines: 100 - gomoddirectives: - replace-allow-list: - - github.com/abbot/go-http-auth - nestif: - min-complexity: 6 - exclusions: - generated: lax - presets: - - comments - - common-false-positives - - legacy - - std-error-handling - rules: - - linters: - - bodyclose - - dogsled - - dupl - - funlen - - gosec - - cyclop - - goconst - - nolintlint - path: _test\.go - paths: - - third_party$ - - builtin$ - - examples$ diff --git a/README.md b/README.md index 863fd4c..ebed6fb 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ogc-specifications -[![Lint](https://github.com/PDOK/ogc-specifications/actions/workflows/lint.yml/badge.svg)](https://github.com/PDOK/ogc-specifications/actions/workflows/lint.yml) + ![GitHub license](https://img.shields.io/github/license/PDOK/ogc-specifications) [![GitHub release](https://img.shields.io/github/release/PDOK/ogc-specifications.svg)](https://github.com/PDOK/ogc-specifications/releases) diff --git a/pkg/utils/xml.go b/pkg/utils/xml.go index 6c6cbe4..16228e6 100644 --- a/pkg/utils/xml.go +++ b/pkg/utils/xml.go @@ -9,13 +9,13 @@ type XMLAttribute []xml.Attr // StripDuplicateAttr removes the duplicate Attributes from a []Attribute func StripDuplicateAttr(attr []xml.Attr) []xml.Attr { - attributeMap := make(map[xml.Name]string) + attributemap := make(map[xml.Name]string) for _, a := range attr { - attributeMap[xml.Name{Space: a.Name.Space, Local: a.Name.Local}] = a.Value + attributemap[xml.Name{Space: a.Name.Space, Local: a.Name.Local}] = a.Value } var strippedAttr []xml.Attr - for k, v := range attributeMap { + for k, v := range attributemap { strippedAttr = append(strippedAttr, xml.Attr{Name: k, Value: v}) } return strippedAttr @@ -23,18 +23,21 @@ func StripDuplicateAttr(attr []xml.Attr) []xml.Attr { // UnmarshalXML func for the XMLAttr struct func (xmlattr *XMLAttribute) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { - var newAttributes XMLAttribute + var newattributes XMLAttribute for _, attr := range start.Attr { - newAttributes = append(newAttributes, xml.Attr{Name: attr.Name, Value: attr.Value}) + switch attr.Name.Local { + default: + newattributes = append(newattributes, xml.Attr{Name: attr.Name, Value: attr.Value}) + } } - *xmlattr = newAttributes + *xmlattr = newattributes for { // if it got this far the XML is 'valid' and the xmlattr are set // so we ignore the err token, _ := d.Token() - - if el, ok := token.(xml.EndElement); ok { + switch el := token.(type) { + case xml.EndElement: if el == start.End() { return nil } diff --git a/pkg/wcs201/capabilities.go b/pkg/wcs201/capabilities.go index 9459850..50947f9 100644 --- a/pkg/wcs201/capabilities.go +++ b/pkg/wcs201/capabilities.go @@ -1,12 +1,12 @@ package wcs201 // ParseXML func -func (c *Capabilities) ParseXML(_ []byte) error { +func (c *Capabilities) ParseXML(doc []byte) error { return nil } // ParseYAML func -func (c *Capabilities) ParseYAML(_ []byte) error { +func (c *Capabilities) ParseYAML(doc []byte) error { return nil } diff --git a/pkg/wcs201/getcapabilities_request.go b/pkg/wcs201/getcapabilities_request.go index 0e889e1..449b37b 100644 --- a/pkg/wcs201/getcapabilities_request.go +++ b/pkg/wcs201/getcapabilities_request.go @@ -23,7 +23,7 @@ func (gc *GetCapabilitiesRequest) Type() string { } // Validate validates the GetCapabilities struct -func (gc *GetCapabilitiesRequest) Validate(_ Capabilities) []wsc200.Exception { +func (gc *GetCapabilitiesRequest) Validate(c Capabilities) []wsc200.Exception { return nil } diff --git a/pkg/wfs200/capabilities.go b/pkg/wfs200/capabilities.go index bcabe19..d41cb3d 100644 --- a/pkg/wfs200/capabilities.go +++ b/pkg/wfs200/capabilities.go @@ -2,17 +2,16 @@ package wfs200 import ( "encoding/xml" - "github.com/pdok/ogc-specifications/pkg/wsc110" ) // ParseXML func -func (c *Capabilities) ParseXML(_ []byte) error { +func (c *Capabilities) ParseXML(doc []byte) error { return nil } // ParseYAML func -func (c *Capabilities) ParseYAML(_ []byte) error { +func (c *Capabilities) ParseYAML(doc []byte) error { return nil } @@ -165,7 +164,7 @@ type MetadataHref struct { // FilterCapabilities struct for the WFS 2.0.0 type FilterCapabilities struct { Conformance Conformance `xml:"fes:Conformance" yaml:"conformance"` - IDCapabilities IDCapabilities `xml:"fes:Id_Capabilities" yaml:"idCapabilities"` + IDCapabilities IdCapabilities `xml:"fes:Id_Capabilities" yaml:"idCapabilities"` ScalarCapabilities ScalarCapabilities `xml:"fes:Scalar_Capabilities" yaml:"scalarCapabilities"` SpatialCapabilities SpatialCapabilities `xml:"fes:Spatial_Capabilities" yaml:"spatialCapabilities"` // NO TemporalCapabilities!!! @@ -177,8 +176,8 @@ type Conformance struct { Constraint []ValueConstraint `xml:"fes:Constraint" yaml:"constraint"` } -// IDCapabilities struct for the WFS 2.0.0 -type IDCapabilities struct { +// IdCapabilities struct for the WFS 2.0.0 +type IdCapabilities struct { ResourceIdentifier ResourceIdentifier `xml:"fes:ResourceIdentifier" yaml:"resourceIdentifier"` } diff --git a/pkg/wfs200/crs.go b/pkg/wfs200/crs.go index f609d62..be84ac5 100644 --- a/pkg/wfs200/crs.go +++ b/pkg/wfs200/crs.go @@ -11,7 +11,7 @@ const ( // CRS struct with namespace/authority/registry and code type CRS struct { - Namespace string // TODO maybe AuthorityType is a better name...? + Namespace string //TODO maybe AuthorityType is a better name...? Code int } diff --git a/pkg/wfs200/crs_test.go b/pkg/wfs200/crs_test.go index b7eed6c..52f3fa2 100644 --- a/pkg/wfs200/crs_test.go +++ b/pkg/wfs200/crs_test.go @@ -51,8 +51,10 @@ othercrs: err := yaml.Unmarshal(test.yaml, &ftl) if err != nil { t.Errorf("test: %d, yaml.UnMarshal failed with '%s'\n", k, err) - } else if ftl.DefaultCRS.Code != test.expectedcrs.Code || ftl.DefaultCRS.Namespace != test.expectedcrs.Namespace { - t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedcrs, ftl.DefaultCRS) + } else { + if ftl.DefaultCRS.Code != test.expectedcrs.Code || ftl.DefaultCRS.Namespace != test.expectedcrs.Namespace { + t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedcrs, ftl.DefaultCRS) + } } } } @@ -68,11 +70,13 @@ func TestMarshalYAMLCrs(t *testing.T) { } for k, test := range tests { yamlCRS, err := yaml.Marshal(test.CRS) - if err != nil { t.Errorf("test: %d, yaml.Marshal failed with '%s'\n", k, err) - } else if stringCRS := string(yamlCRS); stringCRS != test.expectedYAML { - t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedYAML, stringCRS) + } else { + stringCRS := string(yamlCRS) + if stringCRS != test.expectedYAML { + t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedYAML, stringCRS) + } } } } diff --git a/pkg/wfs200/describefeaturetype_request.go b/pkg/wfs200/describefeaturetype_request.go index e1f891f..afe806b 100644 --- a/pkg/wfs200/describefeaturetype_request.go +++ b/pkg/wfs200/describefeaturetype_request.go @@ -21,7 +21,7 @@ func (d DescribeFeatureTypeRequest) Type() string { } // Validate returns GetCapabilities -func (d DescribeFeatureTypeRequest) Validate(_ wsc110.Capabilities) []wsc110.Exception { +func (d DescribeFeatureTypeRequest) Validate(c wsc110.Capabilities) []wsc110.Exception { return nil } diff --git a/pkg/wfs200/describefeaturetype_request_pv.go b/pkg/wfs200/describefeaturetype_request_pv.go index b54d902..40784c3 100644 --- a/pkg/wfs200/describefeaturetype_request_pv.go +++ b/pkg/wfs200/describefeaturetype_request_pv.go @@ -7,10 +7,10 @@ import ( "github.com/pdok/ogc-specifications/pkg/wsc110" ) -//nolint:govet type describeFeatureTypeRequestParameterValue struct { service string `yaml:"service" json:"service"` baseParameterValueRequest + typeName *string `yaml:"typeName" json:"typeName"` // [0..*] outputFormat *string `yaml:"outputFormat" json:"outputFormat"` // default: "text/xml; subtype=gml/3.2" } @@ -45,12 +45,13 @@ func (dpv *describeFeatureTypeRequestParameterValue) parseQueryParameters(query return nil } -func (dpv *describeFeatureTypeRequestParameterValue) parseDescribeFeatureTypeRequest(dft DescribeFeatureTypeRequest) { +func (dpv *describeFeatureTypeRequestParameterValue) parseDescribeFeatureTypeRequest(dft DescribeFeatureTypeRequest) []wsc110.Exception { dpv.request = describefeaturetype dpv.version = dft.Version dpv.service = dft.Service dpv.typeName = dft.TypeNames dpv.outputFormat = dft.OutputFormat + return nil } func (dpv describeFeatureTypeRequestParameterValue) toQueryParameters() url.Values { diff --git a/pkg/wfs200/describefeaturetype_test.go b/pkg/wfs200/describefeaturetype_test.go index 1b97536..29bd9cf 100644 --- a/pkg/wfs200/describefeaturetype_test.go +++ b/pkg/wfs200/describefeaturetype_test.go @@ -15,7 +15,6 @@ func TestDescribeFeatureTypeType(t *testing.T) { } } -//nolint:nestif func TestDescribeFeatureTypeParseXML(t *testing.T) { var tests = []struct { body []byte @@ -101,7 +100,6 @@ func TestDescribeFeatureTypeParseXML(t *testing.T) { } } -//nolint:nestif func TestDescribeFeatureTypeParseQueryParameters(t *testing.T) { var tests = []struct { query url.Values diff --git a/pkg/wfs200/exception.go b/pkg/wfs200/exception.go index 33b18c6..ecd1337 100644 --- a/pkg/wfs200/exception.go +++ b/pkg/wfs200/exception.go @@ -2,7 +2,6 @@ package wfs200 import ( "encoding/xml" - "github.com/pdok/ogc-specifications/pkg/wsc110" ) diff --git a/pkg/wfs200/exception_codes.go b/pkg/wfs200/exception_codes.go index de566c7..0094272 100644 --- a/pkg/wfs200/exception_codes.go +++ b/pkg/wfs200/exception_codes.go @@ -63,7 +63,7 @@ func LockHasExpired() wsc110.Exception { // OperationParsingFailed exception func OperationParsingFailed(value, locator string) wsc110.Exception { return exception{ - ExceptionText: "Failed to parse the operation, found: " + value, + ExceptionText: fmt.Sprintf("Failed to parse the operation, found: %s", value), LocatorCode: locator, ExceptionCode: "OperationParsingFailed"} } diff --git a/pkg/wfs200/getcapabilities_request.go b/pkg/wfs200/getcapabilities_request.go index dd19a76..e89fbb2 100644 --- a/pkg/wfs200/getcapabilities_request.go +++ b/pkg/wfs200/getcapabilities_request.go @@ -18,22 +18,22 @@ func (g GetCapabilitiesRequest) Type() string { } // Validate returns GetCapabilities -func (g GetCapabilitiesRequest) Validate(_ wsc110.Capabilities) []wsc110.Exception { +func (g GetCapabilitiesRequest) Validate(c wsc110.Capabilities) []wsc110.Exception { var exceptions []wsc110.Exception return exceptions } // ParseXML builds a GetCapabilities object based on a XML document func (g *GetCapabilitiesRequest) ParseXML(doc []byte) []wsc110.Exception { - var xmlAttributes utils.XMLAttribute - if err := xml.Unmarshal(doc, &xmlAttributes); err != nil { + var xmlattributes utils.XMLAttribute + if err := xml.Unmarshal(doc, &xmlattributes); err != nil { return []wsc110.Exception{wsc110.NoApplicableCode("Could not process XML, is it XML?")} } if err := xml.Unmarshal(doc, &g); err != nil { - return []wsc110.Exception{wsc110.OperationNotSupported(err.Error())} // TODO Should be OperationParsingFailed + return []wsc110.Exception{wsc110.OperationNotSupported(err.Error())} //TODO Should be OperationParsingFailed } var n []xml.Attr - for _, a := range xmlAttributes { + for _, a := range xmlattributes { switch strings.ToUpper(a.Name.Local) { case VERSION: case SERVICE: @@ -50,7 +50,7 @@ func (g *GetCapabilitiesRequest) ParseXML(doc []byte) []wsc110.Exception { func (g *GetCapabilitiesRequest) ParseQueryParameters(query url.Values) []wsc110.Exception { if len(query) == 0 { // When there are no query value we know that at least - // the mandatory SERVICE and REQUEST parameter is missing. + // the manadorty SERVICE and REQUEST parameter is missing. exceptions := wsc110.MissingParameterValue(SERVICE).ToExceptions() exceptions = append(exceptions, wsc110.MissingParameterValue(REQUEST)) return exceptions @@ -61,15 +61,15 @@ func (g *GetCapabilitiesRequest) ParseQueryParameters(query url.Values) []wsc110 return exception } - if exception := g.parseGetCapabilitiesRequestParameterValue(gpv); exception != nil { + if exception := g.parsegetCapabilitiesRequestParameterValue(gpv); exception != nil { return exception } return nil } -// parseGetCapabilitiesRequestParameterValue process the simple struct to a complex struct -func (g *GetCapabilitiesRequest) parseGetCapabilitiesRequestParameterValue(gpv getCapabilitiesRequestParameterValue) []wsc110.Exception { +// parsegetCapabilitiesRequestParameterValue process the simple struct to a complex struct +func (g *GetCapabilitiesRequest) parsegetCapabilitiesRequestParameterValue(gpv getCapabilitiesRequestParameterValue) []wsc110.Exception { g.XMLName.Local = gpv.request g.Service = gpv.service g.Version = gpv.version diff --git a/pkg/wfs200/getcapabilities_request_pv.go b/pkg/wfs200/getcapabilities_request_pv.go index ab3f561..646d205 100644 --- a/pkg/wfs200/getcapabilities_request_pv.go +++ b/pkg/wfs200/getcapabilities_request_pv.go @@ -7,7 +7,7 @@ import ( "github.com/pdok/ogc-specifications/pkg/wsc110" ) -// getCapabilitiesRequestParameterValue struct +//getCapabilitiesRequestParameterValue struct type getCapabilitiesRequestParameterValue struct { service string `yaml:"service,omitempty"` baseParameterValueRequest @@ -41,14 +41,14 @@ func (gpv *getCapabilitiesRequestParameterValue) parseQueryParameters(query url. // parseGetCapabilitiesRequest builds a getCapabilitiesRequestParameterValue object based on a GetCapabilities struct // This is a 'dummy' implementation, because for a GetCapabilities request it will always be // Mandatory: REQUEST=GetCapabilities -// -// SERVICE=WFS -// +// SERVICE=WFS // Optional: VERSION=2.0.0 -func (gpv *getCapabilitiesRequestParameterValue) parseGetCapabilitiesRequest(gc GetCapabilitiesRequest) { +func (gpv *getCapabilitiesRequestParameterValue) parseGetCapabilitiesRequest(gc GetCapabilitiesRequest) []wsc110.Exception { gpv.request = getcapabilities gpv.version = gc.Version gpv.service = gc.Service + + return nil } // toQueryParameters builds a url.Values query from a getCapabilitiesRequestParameterValue struct diff --git a/pkg/wfs200/getcapabilities_response.go b/pkg/wfs200/getcapabilities_response.go index e7dfa53..e2a993e 100644 --- a/pkg/wfs200/getcapabilities_response.go +++ b/pkg/wfs200/getcapabilities_response.go @@ -47,15 +47,15 @@ type GetCapabilitiesResponse struct { // Namespaces struct containing the namespaces needed for the XML document type Namespaces struct { - XmlnsGML string `xml:"xmlns:gml,attr" yaml:"gml"` // http://www.opengis.net/gml/3.2 - XmlnsWFS string `xml:"xmlns,attr" yaml:"wfs"` // http://www.opengis.net/wfs/2.0 - XmlnsOWS string `xml:"xmlns:ows,attr" yaml:"common"` // http://www.opengis.net/ows/1.1 - XmlnsXlink string `xml:"xmlns:xlink,attr" yaml:"xlink"` // http://www.w3.org/1999/xlink - XmlnsXSI string `xml:"xmlns:xsi,attr" yaml:"xsi"` // http://www.w3.org/2001/XMLSchema-instance - XmlnsFes string `xml:"xmlns:fes,attr" yaml:"fes"` // http://www.opengis.net/fes/2.0 - XmlnsInspireCommon string `xml:"xmlns:inspire_common,attr,omitempty" yaml:"inspireCommon,omitempty"` // http://inspire.ec.europa.eu/schemas/common/1.0 - XmlnsInspireDls string `xml:"xmlns:inspire_dls,attr,omitempty" yaml:"inspireDls,omitempty"` // http://inspire.ec.europa.eu/schemas/inspire_dls/1.0 - XmlnsPrefix string `xml:"xmlns:{{.Prefix}},attr" yaml:"prefix"` // namespace_uri placeholder + XmlnsGML string `xml:"xmlns:gml,attr" yaml:"gml"` //http://www.opengis.net/gml/3.2 + XmlnsWFS string `xml:"xmlns,attr" yaml:"wfs"` //http://www.opengis.net/wfs/2.0 + XmlnsOWS string `xml:"xmlns:ows,attr" yaml:"common"` //http://www.opengis.net/ows/1.1 + XmlnsXlink string `xml:"xmlns:xlink,attr" yaml:"xlink"` //http://www.w3.org/1999/xlink + XmlnsXSI string `xml:"xmlns:xsi,attr" yaml:"xsi"` //http://www.w3.org/2001/XMLSchema-instance + XmlnsFes string `xml:"xmlns:fes,attr" yaml:"fes"` //http://www.opengis.net/fes/2.0 + XmlnsInspireCommon string `xml:"xmlns:inspire_common,attr,omitempty" yaml:"inspireCommon,omitempty"` //http://inspire.ec.europa.eu/schemas/common/1.0 + XmlnsInspireDls string `xml:"xmlns:inspire_dls,attr,omitempty" yaml:"inspireDls,omitempty"` //http://inspire.ec.europa.eu/schemas/inspire_dls/1.0 + XmlnsPrefix string `xml:"xmlns:{{.Prefix}},attr" yaml:"prefix"` //namespace_uri placeholder Version string `xml:"version,attr" yaml:"version"` SchemaLocation string `xml:"xsi:schemaLocation,attr" yaml:"schemaLocation"` } diff --git a/pkg/wfs200/getcapabilities_test.go b/pkg/wfs200/getcapabilities_test.go index 8c6026a..a12abd4 100644 --- a/pkg/wfs200/getcapabilities_test.go +++ b/pkg/wfs200/getcapabilities_test.go @@ -15,7 +15,6 @@ func TestGetCapabilitiesType(t *testing.T) { } } -//nolint:nestif func TestGetCapabilitiesParseXML(t *testing.T) { var tests = []struct { body []byte diff --git a/pkg/wfs200/getfeature_request.go b/pkg/wfs200/getfeature_request.go index 0c6efa8..33b9889 100644 --- a/pkg/wfs200/getfeature_request.go +++ b/pkg/wfs200/getfeature_request.go @@ -54,36 +54,30 @@ func (f GetFeatureRequest) Type() string { } // Validate returns GetFeature -func (f GetFeatureRequest) Validate(_ wsc110.Capabilities) []wsc110.Exception { +func (f GetFeatureRequest) Validate(c wsc110.Capabilities) []wsc110.Exception { - // getfeaturecap := c.(capabilities.Capabilities) + //getfeaturecap := c.(capabilities.Capabilities) return nil } // WFS tables as map[string]bool, where the key (string) is the TOKEN and the bool if its a mandatory (true) or optional (false) attribute -// var table5 = map[string]bool{STARTINDEX: false, COUNT: false, OUTPUTFORMAT: false, RESULTTYPE: false} +//var table5 = map[string]bool{STARTINDEX: false, COUNT: false, OUTPUTFORMAT: false, RESULTTYPE: false} // var table6 = map[string]bool{RESOLVE: false, RESOLVEDEPTH: false, RESOLVETIMEOUT: false} // var table7 = map[string]bool{NAMESPACES: false} //VSPs (<- vendor specific parameters) var table8 = map[string]bool{TYPENAMES: true, ALIASES: false, SRSNAME: false, FILTER: false, FILTERLANGUAGE: false, RESOURCEID: false, BBOX: false, SORTBY: false} -// var table10 = map[string]bool{STOREDQUERYID: true} //storedquery_parameter=value +//var table10 = map[string]bool{STOREDQUERYID: true} //storedquery_parameter=value // ParseXML builds a GetCapabilities object based on a XML document func (f *GetFeatureRequest) ParseXML(doc []byte) []wsc110.Exception { - var xmlAttributes utils.XMLAttribute - if err := xml.Unmarshal(doc, &xmlAttributes); err != nil { + var xmlattributes utils.XMLAttribute + if err := xml.Unmarshal(doc, &xmlattributes); err != nil { return wsc110.NoApplicableCode("Could not process XML, is it XML?").ToExceptions() } - - // When object can be Unmarshalled -> XMLAttributes, it can be Unmarshalled -> GetFeature - // if err := xml.Unmarshal(doc, &f); err != nil { - // return wsc110.NoApplicableCode("Could not process XML, is it XML?").ToExceptions() - // } - _ = xml.Unmarshal(doc, &f) - + xml.Unmarshal(doc, &f) //When object can be Unmarshalled -> XMLAttributes, it can be Unmarshalled -> GetFeature var n []xml.Attr - for _, a := range xmlAttributes { + for _, a := range xmlattributes { switch strings.ToUpper(a.Name.Local) { case VERSION: case SERVICE: @@ -113,7 +107,7 @@ func (f *GetFeatureRequest) ParseQueryParameters(query url.Values) []wsc110.Exce return exceptions } - if exceptions := f.parseGetFeatureRequestParameterValue(fpv); exceptions != nil { + if exceptions := f.parsegetFeatureRequestParameterValue(fpv); exceptions != nil { return exceptions } return nil @@ -126,7 +120,7 @@ func (f GetFeatureRequest) ToXML() []byte { return append([]byte(xml.Header), si...) } -func (f *GetFeatureRequest) parseGetFeatureRequestParameterValue(fpv getFeatureRequestParameterValue) []wsc110.Exception { +func (f *GetFeatureRequest) parsegetFeatureRequestParameterValue(fpv getFeatureRequestParameterValue) []wsc110.Exception { // Base f.XMLName.Local = getfeature @@ -205,7 +199,6 @@ type StandardPresentationParameters struct { StartIndex *int `xml:"startindex,attr,omitempty" yaml:"startIndex"` // default 0 } -//nolint:nestif func (b *StandardPresentationParameters) parseKVPRequest(fpv getFeatureRequestParameterValue) []wsc110.Exception { var exceptions []wsc110.Exception @@ -227,11 +220,11 @@ func (b *StandardPresentationParameters) parseKVPRequest(fpv getFeatureRequestPa } if fpv.startindex != nil { - startIndex, err := strconv.Atoi(*fpv.startindex) + startindex, err := strconv.Atoi(*fpv.startindex) if err != nil { exceptions = append(exceptions, wsc110.MissingParameterValue(STARTINDEX, *fpv.startindex)) } - b.StartIndex = &startIndex + b.StartIndex = &startindex } } @@ -244,7 +237,7 @@ func (b *StandardPresentationParameters) parseKVPRequest(fpv getFeatureRequestPa // StandardResolveParameters struct used by GetFeature // contains the resolve information of a GetFeauter request type StandardResolveParameters struct { - Resolve *string `xml:"Resolve,omitempty" yaml:"resolve"` // can be one of: local, remote, all, none + Resolve *string `xml:"Resolve,omitempty" yaml:"resolve"` //can be one of: local, remote, all, none ResolveDepth *int `xml:"ResolveDepth,omitempty" yaml:"resolveDepth"` ResolveTimeout *int `xml:"ResolveTimeout,omitempty" yaml:"resolveTimeout"` } @@ -267,21 +260,21 @@ func (q *Query) parseKVPRequest(fpv getFeatureRequestParameterValue) []wsc110.Ex q.SrsName = fpv.srsname } - var selectionClause []string + var selectionclause []string if fpv.resourceid != nil { - selectionClause = append(selectionClause, RESOURCEID) + selectionclause = append(selectionclause, RESOURCEID) } if fpv.filter != nil { - selectionClause = append(selectionClause, FILTER) + selectionclause = append(selectionclause, FILTER) } if fpv.bbox != nil { - selectionClause = append(selectionClause, BBOX) + selectionclause = append(selectionclause, BBOX) } - if len(selectionClause) > 1 { - exceptions = append(exceptions, wsc110.NoApplicableCode(`Only one of the following selectionclauses can be used `+strings.Join(selectionClause, `,`))) - } else if len(selectionClause) == 1 { - switch selectionClause[0] { + if len(selectionclause) > 1 { + exceptions = append(exceptions, wsc110.NoApplicableCode(fmt.Sprintf(`Only one of the following selectionclauses can be used %s`, strings.Join(selectionclause, `,`)))) + } else if len(selectionclause) == 1 { + switch selectionclause[0] { case RESOURCEID: f := Filter{} var rids ResourceIDs @@ -307,7 +300,7 @@ func (q *Query) parseKVPRequest(fpv getFeatureRequestParameterValue) []wsc110.Ex // TODO aliases // TODO filterlanguage - // q.SortBy = fpv.sortby + //q.SortBy = fpv.sortby if len(exceptions) > 0 { return exceptions @@ -378,11 +371,11 @@ type Filter struct { func (f Filter) toString() string { si, _ := xml.MarshalIndent(f, "", "") re := regexp.MustCompile(`><.*>`) - return xml.Header + re.ReplaceAllString(string(si), "/>") + return (xml.Header + re.ReplaceAllString(string(si), "/>")) } func (f *Filter) parseKVPRequest(filter string) []wsc110.Exception { - if err := xml.Unmarshal([]byte(filter), &f); err != nil { + if error := xml.Unmarshal([]byte(filter), &f); error != nil { return wsc110.NoApplicableCode(`Filter is not valid XML`).ToExceptions() } return nil @@ -431,12 +424,14 @@ func (r ResourceIDs) toString() string { return strings.Join(rids, ",") } -func (r *ResourceIDs) parseKVPRequest(resourceids string) { +func (r *ResourceIDs) parseKVPRequest(resourceids string) []wsc110.Exception { var rids ResourceIDs for _, resourceid := range strings.Split(resourceids, `,`) { rids = append(rids, ResourceID{Rid: resourceid}) } *r = rids + + return nil } // ResourceID struct for Filter @@ -696,30 +691,31 @@ type GEOBBOX struct { func (gb *GEOBBOX) parseKVPRequest(q string) []wsc110.Exception { regex := regexp.MustCompile(`,`) result := regex.Split(q, -1) + if len(result) == 4 || len(result) == 5 { - if len(result) != 4 && len(result) != 5 { - return wsc110.MissingParameterValue(BBOX, q).ToExceptions() - } - var lx, ly, ux, uy float64 - var err error + var lx, ly, ux, uy float64 + var err error - if lx, err = strconv.ParseFloat(result[0], 64); err != nil { - return InvalidValue(BBOX).ToExceptions() - } - if ly, err = strconv.ParseFloat(result[1], 64); err != nil { - return InvalidValue(BBOX).ToExceptions() - } - if ux, err = strconv.ParseFloat(result[2], 64); err != nil { - return InvalidValue(BBOX).ToExceptions() - } - if uy, err = strconv.ParseFloat(result[3], 64); err != nil { - return InvalidValue(BBOX).ToExceptions() - } + if lx, err = strconv.ParseFloat(result[0], 64); err != nil { + return InvalidValue(BBOX).ToExceptions() + } + if ly, err = strconv.ParseFloat(result[1], 64); err != nil { + return InvalidValue(BBOX).ToExceptions() + } + if ux, err = strconv.ParseFloat(result[2], 64); err != nil { + return InvalidValue(BBOX).ToExceptions() + } + if uy, err = strconv.ParseFloat(result[3], 64); err != nil { + return InvalidValue(BBOX).ToExceptions() + } - gb.Envelope.LowerCorner = wsc110.Position{lx, ly} - gb.Envelope.UpperCorner = wsc110.Position{ux, uy} - if len(result) == 5 { - gb.SrsName = &result[4] + gb.Envelope.LowerCorner = wsc110.Position{lx, ly} + gb.Envelope.UpperCorner = wsc110.Position{ux, uy} + if len(result) == 5 { + gb.SrsName = &result[4] + } + } else { + return wsc110.MissingParameterValue(BBOX, q).ToExceptions() } return nil diff --git a/pkg/wfs200/getfeature_request_pv.go b/pkg/wfs200/getfeature_request_pv.go index 737fa49..9ef7083 100644 --- a/pkg/wfs200/getfeature_request_pv.go +++ b/pkg/wfs200/getfeature_request_pv.go @@ -46,8 +46,6 @@ type standardResolveParameters struct { // AdhocQueryKeywords struct // NOTE filter, resourceid and bbox are mutually exclusive -// -//nolint:tagliatelle type adhocQueryKeywords struct { // Table 8 typenames string `yaml:"typenames"` @@ -68,7 +66,6 @@ type storedQueryKeywords struct { // storedquery_parameter not implemented } -//nolint:cyclop,nestif func (fpv *getFeatureRequestParameterValue) parseQueryParameters(query url.Values) []wsc110.Exception { var exceptions []wsc110.Exception for k, v := range query { @@ -172,8 +169,7 @@ func (fpv *getFeatureRequestParameterValue) parseQueryParameters(query url.Value return nil } -//nolint:cyclop,funlen -func (fpv *getFeatureRequestParameterValue) parseGetFeatureRequest(f GetFeatureRequest) { +func (fpv *getFeatureRequestParameterValue) parseGetFeatureRequest(f GetFeatureRequest) []wsc110.Exception { fpv.request = getfeature fpv.version = Version @@ -250,14 +246,13 @@ func (fpv *getFeatureRequestParameterValue) parseGetFeatureRequest(f GetFeatureR } if f.Query.Filter != nil { - switch { - case f.Query.Filter.ResourceID != nil: + if f.Query.Filter.ResourceID != nil { s := f.Query.Filter.ResourceID.toString() fpv.resourceid = &(s) - case f.Query.Filter.BBOX != nil: + } else if f.Query.Filter.BBOX != nil { s := f.Query.Filter.BBOX.MarshalText() fpv.bbox = &s - default: + } else { f := f.Query.Filter.toString() fpv.filter = &f } @@ -273,9 +268,10 @@ func (fpv *getFeatureRequestParameterValue) parseGetFeatureRequest(f GetFeatureR // TODO // fpv.storedQueryKeywords.storedqueryid = v[0] + + return nil } -//nolint:cyclop func (fpv getFeatureRequestParameterValue) toQueryParameters() url.Values { query := make(map[string][]string) @@ -331,12 +327,11 @@ func (fpv getFeatureRequestParameterValue) toQueryParameters() url.Values { } // // Projection_clause not implemented - switch { - case fpv.filter != nil: + if fpv.filter != nil { query[FILTER] = []string{*fpv.filter} - case fpv.resourceid != nil: + } else if fpv.resourceid != nil { query[RESOURCEID] = []string{*fpv.resourceid} - case fpv.bbox != nil: + } else if fpv.bbox != nil { query[BBOX] = []string{*fpv.bbox} } diff --git a/pkg/wfs200/getfeature_test.go b/pkg/wfs200/getfeature_test.go index dd110c2..900fd47 100644 --- a/pkg/wfs200/getfeature_test.go +++ b/pkg/wfs200/getfeature_test.go @@ -80,8 +80,6 @@ func TestGetFeatureToXML(t *testing.T) { // TODO // Merge TestParseBodyGetFeature & TestParseQueryParameters GetFeature comporison into single func, like with WMS GetMap -// -//nolint:nestif func TestGetFeatureParseXML(t *testing.T) { var tests = []struct { body []byte @@ -216,7 +214,7 @@ func TestProcesNamespaces(t *testing.T) { result: []xml.Attr{{Name: xml.Name{Local: "ns1"}, Value: "http://www.someserver.com/ns1"}}}, // Duplicate namespace with the different values 4: {namespace: "xmlns(ns1,http://www.someserver.com/ns1),xmlns(ns1,http://someserver.com/ns2)", - result: []xml.Attr{{Name: xml.Name{Local: "ns1"}, Value: "http://someserver.com/ns2"}}}, // takes the last matched result + result: []xml.Attr{{Name: xml.Name{Local: "ns1"}, Value: "http://someserver.com/ns2"}}}, //takes the last matched result // A namespace with a trailing string outside the xmlns() 5: {namespace: "xmlns(ns1,http://www.someserver.com/ns1),not a correct,namespace query,string", result: []xml.Attr{{Name: xml.Name{Local: "ns1"}, Value: "http://www.someserver.com/ns1"}}}, @@ -321,7 +319,6 @@ func TestGetFeatureParseQueryParameters(t *testing.T) { } } -//nolint:cyclop,nestif func compareGetFeatureQuery(result, expected GetFeatureRequest, tid int, t *testing.T) { if result.BaseRequest.Service != expected.BaseRequest.Service || result.BaseRequest.Version != expected.BaseRequest.Version { t.Errorf("test: %d, expected: %+v ,\n got: %+v", tid, expected.BaseRequest, result.BaseRequest) @@ -369,8 +366,10 @@ func compareGetFeatureQuery(result, expected GetFeatureRequest, tid int, t *test } if expected.Query.Filter != nil { - if expected.Query.SrsName != nil && *expected.Query.SrsName != *result.Query.SrsName { - t.Errorf("test: %d, expected: %+v ,\n got: %+v", tid, *expected.Query.SrsName, *result.Query.SrsName) + if expected.Query.SrsName != nil { + if *expected.Query.SrsName != *result.Query.SrsName { + t.Errorf("test: %d, expected: %+v ,\n got: %+v", tid, *expected.Query.SrsName, *result.Query.SrsName) + } } if expected.Query.Filter.ResourceID != nil { for _, erid := range *expected.Query.Filter.ResourceID { diff --git a/pkg/wms130/boundingbox_xml.go b/pkg/wms130/boundingbox_xml.go index aae5076..62d5570 100644 --- a/pkg/wms130/boundingbox_xml.go +++ b/pkg/wms130/boundingbox_xml.go @@ -40,7 +40,7 @@ func (p *Position) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { func getPositionFromString(position string) []float64 { regex := regexp.MustCompile(` `) result := regex.Split(position, -1) - var ps []float64 // slice because length can be 2 or more + var ps []float64 //slice because length can be 2 or more // check if 'strings' are parsable to float64 // if one is not return nothing diff --git a/pkg/wms130/boundingbox_yaml_test.go b/pkg/wms130/boundingbox_yaml_test.go index 9aed1ef..8434698 100644 --- a/pkg/wms130/boundingbox_yaml_test.go +++ b/pkg/wms130/boundingbox_yaml_test.go @@ -9,40 +9,44 @@ import ( func TestUnmarshalYAMLPosition(t *testing.T) { var tests = []struct { - positionString []byte - expectedPosition Position + positionstring []byte + expectedposition Position }{ - 0: {positionString: []byte(`2.52712538742158 50.2128625669452`), expectedPosition: Position{2.52712538742158, 50.2128625669452}}, - 1: {positionString: []byte(`7.37402550506231 55.7211602557705`), expectedPosition: Position{7.37402550506231, 55.7211602557705}}, - 2: {positionString: []byte(`7.37402550506231 55.7211602557705 0 1 2 3`), expectedPosition: Position{7.37402550506231, 55.7211602557705}}, + 0: {positionstring: []byte(`2.52712538742158 50.2128625669452`), expectedposition: Position{2.52712538742158, 50.2128625669452}}, + 1: {positionstring: []byte(`7.37402550506231 55.7211602557705`), expectedposition: Position{7.37402550506231, 55.7211602557705}}, + 2: {positionstring: []byte(`7.37402550506231 55.7211602557705 0 1 2 3`), expectedposition: Position{7.37402550506231, 55.7211602557705}}, } for k, test := range tests { var pos Position - err := yaml.Unmarshal(test.positionString, &pos) + err := yaml.Unmarshal(test.positionstring, &pos) if err != nil { t.Errorf("test: %d, yaml.UnMarshal failed with '%s'\n", k, err) - } else if pos != test.expectedPosition { - t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedPosition, pos) + } else { + if pos != test.expectedposition { + t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedposition, pos) + } } } } func TestMarshalYAMLPosition(t *testing.T) { var tests = []struct { - positionString []byte + positionstring []byte position Position }{ - 0: {positionString: []byte("2.52712538742158 50.2128625669452\n"), position: Position{2.52712538742158, 50.2128625669452}}, - 1: {positionString: []byte("7.37402550506231 55.7211602557705\n"), position: Position{7.37402550506231, 55.7211602557705}}, + 0: {positionstring: []byte("2.52712538742158 50.2128625669452\n"), position: Position{2.52712538742158, 50.2128625669452}}, + 1: {positionstring: []byte("7.37402550506231 55.7211602557705\n"), position: Position{7.37402550506231, 55.7211602557705}}, } for k, test := range tests { pos, err := yaml.Marshal(test.position) if err != nil { t.Errorf("test: %d, yaml.Marshal failed with '%s'\n", k, err) - } else if string(pos) != string(test.positionString) { - t.Errorf("test: %d, expected: %s,\n got: %s", k, test.positionString, pos) + } else { + if string(pos) != string(test.positionstring) { + t.Errorf("test: %d, expected: %s,\n got: %s", k, test.positionstring, pos) + } } } } diff --git a/pkg/wms130/capabilities.go b/pkg/wms130/capabilities.go index c173bbe..b500819 100644 --- a/pkg/wms130/capabilities.go +++ b/pkg/wms130/capabilities.go @@ -32,11 +32,9 @@ type Capabilities struct { } // WMSCapabilities base struct -// -//nolint:tagliatelle type WMSCapabilities struct { Request Request `xml:"Request" yaml:"request"` - Exception ExceptionType `xml:"Exception" yaml:"Exception"` + Exception ExceptionType `xml:"Exception" yaml:"exception"` ExtendedCapabilities *ExtendedCapabilities `xml:"inspire_vs:ExtendedCapabilities" yaml:"extendedCapabilities,omitempty"` Layer []Layer `xml:"Layer" yaml:"layer"` } @@ -68,7 +66,7 @@ type Layer struct { // layer has a full/complete map coverage Opaque *string `xml:"opaque,attr" yaml:"opaque,omitempty"` // no cascaded attr in Layer element, because we don't do cascaded services e.g. wms services "proxying" and/or combining other wms services - // Cascaded *string `xml:"cascaded,attr" yaml:"cascaded"` + //Cascaded *string `xml:"cascaded,attr" yaml:"cascaded"` Name *string `xml:"Name" yaml:"name,omitempty"` Title string `xml:"Title" yaml:"title"` Abstract *string `xml:"Abstract,omitempty" yaml:"abstract,omitempty"` @@ -180,7 +178,7 @@ func (l *Layer) findLayer(layername string) *Layer { } // GetLayer returns the Layer Capabilities from the Capabilities document. -// when the requested Layer is not found a Exception is thrown. +// when the requested Layer is not found a exception is thrown. func (c *Capabilities) GetLayer(layername string) (Layer, Exceptions) { var layer Layer diff --git a/pkg/wms130/common.go b/pkg/wms130/common.go index 6bdeec3..311980c 100644 --- a/pkg/wms130/common.go +++ b/pkg/wms130/common.go @@ -56,8 +56,6 @@ func (b *BaseRequest) ParseQueryParameters(q url.Values) Exceptions { } // parseBaseParameterValueRequest builds a BaseRequest struct -// -//nolint:unparam func (b *BaseRequest) parseBaseParameterValueRequest(bpv baseParameterValueRequest) Exceptions { // Service is optional, because it's implicit for a GetMap/GetFeatureInfo request b.Service = Service diff --git a/pkg/wms130/crs.go b/pkg/wms130/crs.go index 3071593..3ba9d46 100644 --- a/pkg/wms130/crs.go +++ b/pkg/wms130/crs.go @@ -16,7 +16,7 @@ const ( // CRS struct with namespace/authority/registry and code type CRS struct { - Namespace string // TODO maybe AuthorityType is a better name...? + Namespace string //TODO maybe AuthorityType is a better name...? Code int } diff --git a/pkg/wms130/crs_test.go b/pkg/wms130/crs_test.go index 19ff4bb..d664c93 100644 --- a/pkg/wms130/crs_test.go +++ b/pkg/wms130/crs_test.go @@ -31,8 +31,10 @@ othercrs: err := yaml.Unmarshal(test.yaml, &ftl) if err != nil { t.Errorf("test: %d, yaml.UnMarshal failed with '%s'\n", k, err) - } else if ftl.DefaultCRS.Code != test.expectedCrs.Code || ftl.DefaultCRS.Namespace != test.expectedCrs.Namespace { - t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedCrs, ftl.DefaultCRS) + } else { + if ftl.DefaultCRS.Code != test.expectedCrs.Code || ftl.DefaultCRS.Namespace != test.expectedCrs.Namespace { + t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedCrs, ftl.DefaultCRS) + } } } } diff --git a/pkg/wms130/exception.go b/pkg/wms130/exception.go index 28eddb0..04f4655 100644 --- a/pkg/wms130/exception.go +++ b/pkg/wms130/exception.go @@ -2,19 +2,16 @@ package wms130 import ( "encoding/xml" - "github.com/pdok/ogc-specifications/pkg/common" ) -// Exception -// -//nolint:errname -type Exception struct { +// exception +type exception struct { common.ExceptionDetails } -// Exceptions is an array of the Exception interface -type Exceptions []Exception +// Exceptions is a array of the Exception interface +type Exceptions []exception // ServiceExceptionReport struct type ServiceExceptionReport struct { @@ -43,22 +40,22 @@ func (r ServiceExceptionReport) ToBytes() []byte { return append([]byte(xml.Header), si...) } -// ToExceptions promotes a single Exception to an array of one -func (e Exception) ToExceptions() Exceptions { +// ToExceptions promotes a single exception to an array of one +func (e exception) ToExceptions() Exceptions { return Exceptions{e} } // Error returns available ExceptionText -func (e Exception) Error() string { +func (e exception) Error() string { return e.ExceptionText } // Code returns available ExceptionCode -func (e Exception) Code() string { +func (e exception) Code() string { return e.ExceptionCode } // Locator returns available ExceptionCode -func (e Exception) Locator() string { +func (e exception) Locator() string { return e.LocatorCode } diff --git a/pkg/wms130/exception_codes.go b/pkg/wms130/exception_codes.go index 5edc652..23bfdb6 100644 --- a/pkg/wms130/exception_codes.go +++ b/pkg/wms130/exception_codes.go @@ -2,150 +2,152 @@ package wms130 import ( "fmt" - "github.com/pdok/ogc-specifications/pkg/common" ) -// InvalidFormat Exception -func InvalidFormat(unknownFormat string) Exception { - return Exception{ExceptionDetails: common.ExceptionDetails{ - ExceptionText: fmt.Sprintf("The format: %s, is a invalid image format", unknownFormat), +// InvalidFormat exception +func InvalidFormat(unknownformat string) exception { + return exception{ExceptionDetails: common.ExceptionDetails{ + ExceptionText: fmt.Sprintf("The format: %s, is a invalid image format", unknownformat), ExceptionCode: `InvalidFormat`, }} } -// InvalidCRS Exception -func InvalidCRS(s ...string) Exception { +// InvalidCRS exception +func InvalidCRS(s ...string) exception { if len(s) == 1 { - return Exception{ExceptionDetails: common.ExceptionDetails{ - ExceptionText: "CRS is not known by this service: " + s[0], + return exception{ExceptionDetails: common.ExceptionDetails{ + ExceptionText: fmt.Sprintf("CRS is not known by this service: %s", s[0]), ExceptionCode: `InvalidCRS`, }} } if len(s) == 2 { - return Exception{ExceptionDetails: common.ExceptionDetails{ + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionText: fmt.Sprintf("The CRS: %s is not known by the layer: %s", s[0], s[1]), ExceptionCode: `InvalidCRS`, }} } - return Exception{ExceptionDetails: common.ExceptionDetails{ + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionCode: `InvalidCRS`, }} } -// LayerNotDefined Exception -func LayerNotDefined(s ...string) Exception { +// LayerNotDefined exception +func LayerNotDefined(s ...string) exception { if len(s) == 1 { - return Exception{ExceptionDetails: common.ExceptionDetails{ + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionText: fmt.Sprintf("The layer: %s is not known by the server", s[0]), ExceptionCode: `LayerNotDefined`, }} } - return Exception{ExceptionDetails: common.ExceptionDetails{ + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionCode: `LayerNotDefined`, }} } -// StyleNotDefined Exception -func StyleNotDefined(s ...string) Exception { +// StyleNotDefined exception +func StyleNotDefined(s ...string) exception { if len(s) == 2 { - return Exception{ExceptionDetails: common.ExceptionDetails{ + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionText: fmt.Sprintf("The style: %s is not known by the server for the layer: %s", s[0], s[1]), ExceptionCode: `StyleNotDefined`, }} } - return Exception{ExceptionDetails: common.ExceptionDetails{ + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionText: `There is a one-to-one correspondence between the values in the LAYERS parameter and the values in the STYLES parameter. Expecting an empty string for the STYLES like STYLES= or comma-separated list STYLES=,,, or using keyword default STYLES=default,default,...`, ExceptionCode: `StyleNotDefined`, }} } -// LayerNotQueryable Exception -func LayerNotQueryable(s ...string) Exception { +// LayerNotQueryable exception +func LayerNotQueryable(s ...string) exception { if len(s) == 1 { - return Exception{ExceptionDetails: common.ExceptionDetails{ + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionText: fmt.Sprintf("Layer: %s, can not be queried", s[0]), ExceptionCode: `LayerNotQueryable`, LocatorCode: s[0], }} } - return Exception{ExceptionDetails: common.ExceptionDetails{ + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionCode: `LayerNotQueryable`, }} } -// InvalidPoint Exception -// i and j are strings so we can return none integer values in the Exception -func InvalidPoint(i, j string) Exception { +// InvalidPoint exception +// i and j are strings so we can return none integer values in the exception +func InvalidPoint(i, j string) exception { // TODO provide giving WIDTH and HEIGHT values in Exception response - return Exception{ExceptionDetails: common.ExceptionDetails{ + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionText: fmt.Sprintf("The parameters I and J are invalid, given: %s for I and %s for J", i, j), ExceptionCode: `InvalidPoint`, }} } -// CurrentUpdateSequence Exception -func CurrentUpdateSequence() Exception { - return Exception{ExceptionDetails: common.ExceptionDetails{ +// CurrentUpdateSequence exception +func CurrentUpdateSequence() exception { + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionCode: `CurrentUpdateSequence`, }} } -// InvalidUpdateSequence Exception -func InvalidUpdateSequence() Exception { - return Exception{ExceptionDetails: common.ExceptionDetails{ +// InvalidUpdateSequence exception +func InvalidUpdateSequence() exception { + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionCode: `InvalidUpdateSequence`, }} } -// MissingDimensionValue Exception -func MissingDimensionValue() Exception { - return Exception{ExceptionDetails: common.ExceptionDetails{ +// MissingDimensionValue exception +func MissingDimensionValue() exception { + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionCode: `MissingDimensionValue`, }} } -// InvalidDimensionValue Exception -func InvalidDimensionValue() Exception { - return Exception{ExceptionDetails: common.ExceptionDetails{ +// InvalidDimensionValue exception +func InvalidDimensionValue() exception { + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionCode: `InvalidDimensionValue`, }} } -// MissingParameterValue Exception -func MissingParameterValue(s ...string) Exception { +//////////////// +//////////////// + +// MissingParameterValue exception +func MissingParameterValue(s ...string) exception { if len(s) >= 2 { - return Exception{ExceptionDetails: common.ExceptionDetails{ExceptionText: fmt.Sprintf("%s key got incorrect value: %s", s[0], s[1]), ExceptionCode: "MissingParameterValue", LocatorCode: s[0]}} + return exception{ExceptionDetails: common.ExceptionDetails{ExceptionText: fmt.Sprintf("%s key got incorrect value: %s", s[0], s[1]), ExceptionCode: "MissingParameterValue", LocatorCode: s[0]}} } if len(s) == 1 { - return Exception{ExceptionDetails: common.ExceptionDetails{ExceptionText: "Missing key: " + s[0], ExceptionCode: "MissingParameterValue", LocatorCode: s[0]}} + return exception{ExceptionDetails: common.ExceptionDetails{ExceptionText: fmt.Sprintf("Missing key: %s", s[0]), ExceptionCode: "MissingParameterValue", LocatorCode: s[0]}} } - return Exception{ExceptionDetails: common.ExceptionDetails{ExceptionText: `Could not determine REQUEST`, ExceptionCode: "MissingParameterValue", LocatorCode: "REQUEST"}} + return exception{ExceptionDetails: common.ExceptionDetails{ExceptionText: `Could not determine REQUEST`, ExceptionCode: "MissingParameterValue", LocatorCode: "REQUEST"}} } -// InvalidParameterValue Exception -func InvalidParameterValue(value, locator string) Exception { - return Exception{ExceptionDetails: common.ExceptionDetails{ +// InvalidParameterValue exception +func InvalidParameterValue(value, locator string) exception { + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionText: fmt.Sprintf("%s contains a invalid value: %s", locator, value), LocatorCode: value, ExceptionCode: `InvalidParameterValue`, }} } -// NoApplicableCode Exception -func NoApplicableCode(message string) Exception { - return Exception{ExceptionDetails: common.ExceptionDetails{ +// NoApplicableCode exception +func NoApplicableCode(message string) exception { + return exception{ExceptionDetails: common.ExceptionDetails{ ExceptionText: message, ExceptionCode: `NoApplicableCode`, }} } -// OperationNotSupported Exception -func OperationNotSupported(message string) Exception { - return Exception{ExceptionDetails: common.ExceptionDetails{ - ExceptionText: "This service does not know the operation: " + message, +// OperationNotSupported exception +func OperationNotSupported(message string) exception { + return exception{ExceptionDetails: common.ExceptionDetails{ + ExceptionText: fmt.Sprintf("This service does not know the operation: %s", message), ExceptionCode: `OperationNotSupported`, LocatorCode: message, }} diff --git a/pkg/wms130/exception_test.go b/pkg/wms130/exception_test.go index 3359c42..d35a322 100644 --- a/pkg/wms130/exception_test.go +++ b/pkg/wms130/exception_test.go @@ -1,19 +1,18 @@ package wms130 import ( - "testing" - "github.com/pdok/ogc-specifications/pkg/common" + "testing" ) func TestWFSException(t *testing.T) { var tests = []struct { - exception Exception + exception exception exceptionText string exceptionCode string locatorCode string }{ - 0: {exception: Exception{ExceptionDetails: common.ExceptionDetails{ExceptionCode: "", ExceptionText: "", LocatorCode: ""}}, + 0: {exception: exception{ExceptionDetails: common.ExceptionDetails{ExceptionCode: "", ExceptionText: "", LocatorCode: ""}}, exceptionText: "", exceptionCode: "", locatorCode: "", @@ -81,7 +80,7 @@ func TestReport(t *testing.T) { result []byte err error }{ - 0: {exceptions: Exceptions{Exception{ExceptionDetails: common.ExceptionDetails{ExceptionCode: "", ExceptionText: "", LocatorCode: ""}}}, + 0: {exceptions: Exceptions{exception{ExceptionDetails: common.ExceptionDetails{ExceptionCode: "", ExceptionText: "", LocatorCode: ""}}}, result: []byte(` diff --git a/pkg/wms130/getcapabilities_request.go b/pkg/wms130/getcapabilities_request.go index 254939d..b5ea330 100644 --- a/pkg/wms130/getcapabilities_request.go +++ b/pkg/wms130/getcapabilities_request.go @@ -16,7 +16,7 @@ type GetCapabilitiesRequest struct { } // Validate returns GetCapabilities -func (g *GetCapabilitiesRequest) Validate(_ Capabilities) Exceptions { +func (g *GetCapabilitiesRequest) Validate(c Capabilities) Exceptions { var exceptions Exceptions return exceptions } @@ -57,15 +57,15 @@ func (g *GetCapabilitiesRequest) ParseQueryParameters(query url.Values) Exceptio return exception } - if exception := g.parseGetCapabilitiesRequestParameterValue(gpv); exception != nil { + if exception := g.parsegetCapabilitiesRequestParameterValue(gpv); exception != nil { return exception } return nil } -// parseGetCapabilitiesRequestParameterValue process the simple struct to a complex struct -func (g *GetCapabilitiesRequest) parseGetCapabilitiesRequestParameterValue(gpv getCapabilitiesRequestParameterValue) Exceptions { +// parsegetCapabilitiesRequestParameterValue process the simple struct to a complex struct +func (g *GetCapabilitiesRequest) parsegetCapabilitiesRequestParameterValue(gpv getCapabilitiesRequestParameterValue) Exceptions { g.XMLName.Local = gpv.request g.BaseRequest.parseBaseParameterValueRequest(gpv.baseParameterValueRequest) diff --git a/pkg/wms130/getcapabilities_request_pv.go b/pkg/wms130/getcapabilities_request_pv.go index d48c117..6741409 100644 --- a/pkg/wms130/getcapabilities_request_pv.go +++ b/pkg/wms130/getcapabilities_request_pv.go @@ -5,7 +5,7 @@ import ( "strings" ) -// getCapabilitiesRequestParameterValue struct +//getCapabilitiesRequestParameterValue struct type getCapabilitiesRequestParameterValue struct { // Table 8 - The Parameters of a GetMap request service string `yaml:"service,omitempty"` @@ -40,14 +40,14 @@ func (gpv *getCapabilitiesRequestParameterValue) parseQueryParameters(query url. // ParseOperationRequest builds a getCapabilitiesRequestParameterValue object based on a GetCapabilities struct // This is a 'dummy' implementation, because for a GetCapabilities request it will always be // Mandatory: REQUEST=GetCapabilities -// -// SERVICE=WMS -// +// SERVICE=WMS // Optional: VERSION=1.3.0 -func (gpv *getCapabilitiesRequestParameterValue) parseGetCapabilitiesRequest(g GetCapabilitiesRequest) { +func (gpv *getCapabilitiesRequestParameterValue) parseGetCapabilitiesRequest(g GetCapabilitiesRequest) Exceptions { gpv.request = getcapabilities gpv.version = g.Version gpv.service = g.Service + + return nil } // toQueryParameters builds a url.Values query from a getCapabilitiesRequestParameterValue struct diff --git a/pkg/wms130/getcapabilities_test.go b/pkg/wms130/getcapabilities_test.go index fd164a2..fef6c71 100644 --- a/pkg/wms130/getcapabilities_test.go +++ b/pkg/wms130/getcapabilities_test.go @@ -6,7 +6,6 @@ import ( "testing" ) -//nolint:nestif func TestGetCapabilitiesParseXML(t *testing.T) { var tests = []struct { body []byte @@ -60,7 +59,6 @@ func TestGetCapabilitiesParseXML(t *testing.T) { } } -//nolint:nestif func TestGetCapabilitiesParseQueryParameters(t *testing.T) { var tests = []struct { query url.Values @@ -97,7 +95,7 @@ func TestGetCapabilitiesParseQueryParameters(t *testing.T) { } } if !found { - t.Errorf("test Exception: %d, expected one of: %s ,\n got: %s", k, test.exceptions, exception.Error()) + t.Errorf("test exception: %d, expected one of: %s ,\n got: %s", k, test.exceptions, exception.Error()) } } } else { diff --git a/pkg/wms130/getfeatureinfo_request.go b/pkg/wms130/getfeatureinfo_request.go index 6a79128..3631688 100644 --- a/pkg/wms130/getfeatureinfo_request.go +++ b/pkg/wms130/getfeatureinfo_request.go @@ -30,7 +30,7 @@ type GetFeatureInfoRequest struct { // // These are the 'minimum' required GetMap parameters // needed in a GetFeatureInfo request - StyledLayerDescriptor StyledLayerDescriptor `xml:"StyledLayerDescriptor" yaml:"styledLayerDescriptor"` // TODO layers is need styles is not! + StyledLayerDescriptor StyledLayerDescriptor `xml:"StyledLayerDescriptor" yaml:"styledLayerDescriptor"` //TODO layers is need styles is not! CRS string `xml:"CRS" yaml:"crs"` BoundingBox BoundingBox `xml:"BoundingBox" yaml:"boundingBox"` // We skip the Output struct, because these are not required parameters @@ -48,11 +48,11 @@ type GetFeatureInfoRequest struct { } // Validate returns GetFeatureInfo -func (gfi *GetFeatureInfoRequest) Validate(c Capabilities) Exceptions { +func (i *GetFeatureInfoRequest) Validate(c Capabilities) Exceptions { var exceptions Exceptions - exceptions = append(exceptions, gfi.StyledLayerDescriptor.Validate(c)...) - // exceptions = append(exceptions, gfi.Output.Validate(wmsCapabilities)...) + exceptions = append(exceptions, i.StyledLayerDescriptor.Validate(c)...) + // exceptions = append(exceptions, i.Output.Validate(wmsCapabilities)...) return exceptions } @@ -61,16 +61,16 @@ func (gfi *GetFeatureInfoRequest) Validate(c Capabilities) Exceptions { // Note: the XML GetFeatureInfo body that is consumed is a interpretation. // So we use the GetMap, that is a large part of this request, as a base // with the additional GetFeatureInfo parameters. -func (gfi *GetFeatureInfoRequest) ParseXML(body []byte) Exceptions { - var xmlAttributes utils.XMLAttribute - if err := xml.Unmarshal(body, &xmlAttributes); err != nil { +func (i *GetFeatureInfoRequest) ParseXML(body []byte) Exceptions { + var xmlattributes utils.XMLAttribute + if err := xml.Unmarshal(body, &xmlattributes); err != nil { return Exceptions{MissingParameterValue()} } - if err := xml.Unmarshal(body, &gfi); err != nil { + if err := xml.Unmarshal(body, &i); err != nil { return Exceptions{MissingParameterValue("REQUEST")} } var n []xml.Attr - for _, a := range xmlAttributes { + for _, a := range xmlattributes { switch strings.ToUpper(a.Name.Local) { case VERSION: case SERVICE: @@ -79,53 +79,53 @@ func (gfi *GetFeatureInfoRequest) ParseXML(body []byte) Exceptions { } } - gfi.Attr = utils.StripDuplicateAttr(n) + i.Attr = utils.StripDuplicateAttr(n) return nil } -// parseGetFeatureInfoRequestParameterValue process the simple struct to a complex struct -func (gfi *GetFeatureInfoRequest) parseGetFeatureInfoRequestParameterValue(ipv getFeatureInfoRequestParameterValue) Exceptions { +// parsegetFeatureInfoRequestParameterValue process the simple struct to a complex struct +func (i *GetFeatureInfoRequest) parsegetFeatureInfoRequestParameterValue(ipv getFeatureInfoRequestParameterValue) Exceptions { var exceptions Exceptions - gfi.XMLName.Local = getfeatureinfo - gfi.BaseRequest.parseBaseParameterValueRequest(ipv.baseParameterValueRequest) + i.XMLName.Local = getfeatureinfo + i.BaseRequest.parseBaseParameterValueRequest(ipv.baseParameterValueRequest) sld, ex := ipv.buildStyledLayerDescriptor() if ex != nil { exceptions = append(exceptions, ex...) } - gfi.StyledLayerDescriptor = sld + i.StyledLayerDescriptor = sld - gfi.CRS = ipv.crs + i.CRS = ipv.crs var bbox BoundingBox if ex := bbox.parseString(ipv.bbox); ex != nil { exceptions = append(exceptions, ex...) } - gfi.BoundingBox = bbox + i.BoundingBox = bbox - gfi.CRS = ipv.crs + i.CRS = ipv.crs w, err := strconv.Atoi(ipv.width) if err != nil { exceptions = append(exceptions, Exceptions{MissingParameterValue(WIDTH, ipv.width)}...) } - gfi.Size.Width = w + i.Size.Width = w h, err := strconv.Atoi(ipv.height) if err != nil { exceptions = append(exceptions, Exceptions{MissingParameterValue(HEIGHT, ipv.height)}...) } - gfi.Size.Height = h + i.Size.Height = h - gfi.QueryLayers = strings.Split(ipv.querylayers, ",") + i.QueryLayers = strings.Split(ipv.querylayers, ",") - if exps := gfi.parseIJ(ipv.i, ipv.j); exps != nil { + if exps := i.parseIJ(ipv.i, ipv.j); exps != nil { exceptions = append(exceptions, exps...) } - gfi.InfoFormat = ipv.infoformat + i.InfoFormat = ipv.infoformat // Optional keys if ipv.featurecount != nil { @@ -134,11 +134,11 @@ func (gfi *GetFeatureInfoRequest) parseGetFeatureInfoRequestParameterValue(ipv g exceptions = append(exceptions, NoApplicableCode("Unknown FEATURE_COUNT value")) } - gfi.FeatureCount = &fc + i.FeatureCount = &fc } if ipv.exceptions != nil { - gfi.Exceptions = ipv.exceptions + i.Exceptions = ipv.exceptions } if len(exceptions) > 0 { @@ -148,7 +148,7 @@ func (gfi *GetFeatureInfoRequest) parseGetFeatureInfoRequestParameterValue(ipv g } // ParseQueryParameters builds a GetFeatureInfo object based on the available query parameters -func (gfi *GetFeatureInfoRequest) ParseQueryParameters(query url.Values) Exceptions { +func (i *GetFeatureInfoRequest) ParseQueryParameters(query url.Values) Exceptions { if len(query) == 0 { // When there are no query value we know that at least // the manadorty VERSION and REQUEST parameter is missing. @@ -160,7 +160,7 @@ func (gfi *GetFeatureInfoRequest) ParseQueryParameters(query url.Values) Excepti return exceptions } - if exceptions := gfi.parseGetFeatureInfoRequestParameterValue(ipv); len(exceptions) != 0 { + if exceptions := i.parsegetFeatureInfoRequestParameterValue(ipv); len(exceptions) != 0 { return exceptions } @@ -168,9 +168,9 @@ func (gfi *GetFeatureInfoRequest) ParseQueryParameters(query url.Values) Excepti } // ToQueryParameters builds a new query string that will be proxied -func (gfi *GetFeatureInfoRequest) ToQueryParameters() url.Values { +func (i GetFeatureInfoRequest) ToQueryParameters() url.Values { ipv := getFeatureInfoRequestParameterValue{} - ipv.parseGetFeatureInfoRequest(*gfi) + ipv.parseGetFeatureInfoRequest(i) q := ipv.toQueryParameters() return q @@ -180,24 +180,24 @@ func (gfi *GetFeatureInfoRequest) ToQueryParameters() url.Values { // Note: this GetFeatureInfo XML body is a interpretation and there isn't a // good/real OGC example request. So for now we use the GetMap, that is a large part // of this request, as a base with the additional GetFeatureInfo parameters. -func (gfi *GetFeatureInfoRequest) ToXML() []byte { - si, _ := xml.MarshalIndent(gfi, "", " ") +func (i GetFeatureInfoRequest) ToXML() []byte { + si, _ := xml.MarshalIndent(i, "", " ") re := regexp.MustCompile(`><.*>`) return []byte(xml.Header + re.ReplaceAllString(string(si), "/>")) } -func (gfi *GetFeatureInfoRequest) parseIJ(i string, j string) Exceptions { - ii, err := strconv.Atoi(i) +func (i *GetFeatureInfoRequest) parseIJ(I, J string) Exceptions { + ii, err := strconv.Atoi(I) if err != nil { - return InvalidPoint(i, j).ToExceptions() + return InvalidPoint(I, J).ToExceptions() } - gfi.I = ii + i.I = ii - jj, err := strconv.Atoi(j) + j, err := strconv.Atoi(J) if err != nil { - return InvalidPoint(i, j).ToExceptions() + return InvalidPoint(I, J).ToExceptions() } - gfi.J = jj + i.J = j return nil } diff --git a/pkg/wms130/getfeatureinfo_request_pv.go b/pkg/wms130/getfeatureinfo_request_pv.go index ffe0c97..11de5ae 100644 --- a/pkg/wms130/getfeatureinfo_request_pv.go +++ b/pkg/wms130/getfeatureinfo_request_pv.go @@ -17,47 +17,46 @@ type getFeatureInfoRequestParameterValue struct { } // parseQueryParameters builds a getFeatureInfoRequestParameterValue object based on the available query parameters -// -//nolint:cyclop -func (ipv *getFeatureInfoRequestParameterValue) parseQueryParameters(query url.Values) (exceptions Exceptions) { +func (ipv *getFeatureInfoRequestParameterValue) parseQueryParameters(query url.Values) Exceptions { + var exceptions Exceptions for k, v := range query { if len(v) != 1 { exceptions = append(exceptions, InvalidParameterValue(k, strings.Join(v, ","))) - continue - } - switch strings.ToUpper(k) { - case SERVICE: - ipv.service = strings.ToUpper(v[0]) - case VERSION: - ipv.baseParameterValueRequest.version = v[0] - case REQUEST: - ipv.baseParameterValueRequest.request = v[0] - case LAYERS: - ipv.getMapParameterValueMandatory.layers = v[0] - case STYLES: - ipv.getMapParameterValueMandatory.styles = v[0] - case "CRS": - ipv.getMapParameterValueMandatory.crs = v[0] - case BBOX: - ipv.getMapParameterValueMandatory.bbox = v[0] - case WIDTH: - ipv.getMapParameterValueMandatory.width = v[0] - case HEIGHT: - ipv.getMapParameterValueMandatory.height = v[0] - case FORMAT: - ipv.getMapParameterValueMandatory.format = v[0] - case QUERYLAYERS: - ipv.getFeatureInfoParameterValueMandatory.querylayers = v[0] - case INFOFORMAT: - ipv.getFeatureInfoParameterValueMandatory.infoformat = v[0] - case I: - ipv.getFeatureInfoParameterValueMandatory.i = v[0] - case J: - ipv.getFeatureInfoParameterValueMandatory.j = v[0] - case FEATURECOUNT: - ipv.getFeatureInfoParameterValueOptional.featurecount = &(v[0]) - case EXCEPTIONS: - ipv.getFeatureInfoParameterValueOptional.exceptions = &(v[0]) + } else { + switch strings.ToUpper(k) { + case SERVICE: + ipv.service = strings.ToUpper(v[0]) + case VERSION: + ipv.baseParameterValueRequest.version = v[0] + case REQUEST: + ipv.baseParameterValueRequest.request = v[0] + case LAYERS: + ipv.getMapParameterValueMandatory.layers = v[0] + case STYLES: + ipv.getMapParameterValueMandatory.styles = v[0] + case "CRS": + ipv.getMapParameterValueMandatory.crs = v[0] + case BBOX: + ipv.getMapParameterValueMandatory.bbox = v[0] + case WIDTH: + ipv.getMapParameterValueMandatory.width = v[0] + case HEIGHT: + ipv.getMapParameterValueMandatory.height = v[0] + case FORMAT: + ipv.getMapParameterValueMandatory.format = v[0] + case QUERYLAYERS: + ipv.getFeatureInfoParameterValueMandatory.querylayers = v[0] + case INFOFORMAT: + ipv.getFeatureInfoParameterValueMandatory.infoformat = v[0] + case I: + ipv.getFeatureInfoParameterValueMandatory.i = v[0] + case J: + ipv.getFeatureInfoParameterValueMandatory.j = v[0] + case FEATURECOUNT: + ipv.getFeatureInfoParameterValueOptional.featurecount = &(v[0]) + case EXCEPTIONS: + ipv.getFeatureInfoParameterValueOptional.exceptions = &(v[0]) + } } } @@ -102,7 +101,7 @@ func (ipv getFeatureInfoRequestParameterValue) toQueryParameters() url.Values { } // parseGetFeatureInfoRequest builds a getFeatureInfoRequestParameterValue object based on a GetFeatureInfoRequest struct -func (ipv *getFeatureInfoRequestParameterValue) parseGetFeatureInfoRequest(i GetFeatureInfoRequest) { +func (ipv *getFeatureInfoRequestParameterValue) parseGetFeatureInfoRequest(i GetFeatureInfoRequest) Exceptions { ipv.request = getfeatureinfo ipv.version = Version @@ -127,6 +126,8 @@ func (ipv *getFeatureInfoRequestParameterValue) parseGetFeatureInfoRequest(i Get } ipv.exceptions = i.Exceptions + + return nil } // GetFeatureInfoParameterValueMandatory struct containing the mandatory WMS request Parameter Value diff --git a/pkg/wms130/getfeatureinfo_test.go b/pkg/wms130/getfeatureinfo_test.go index f229a83..f3c9ecf 100644 --- a/pkg/wms130/getfeatureinfo_test.go +++ b/pkg/wms130/getfeatureinfo_test.go @@ -2,7 +2,6 @@ package wms130 import ( "encoding/xml" - "errors" "net/url" "strings" "testing" @@ -149,8 +148,8 @@ func TestGetFeatureInfoToXML(t *testing.T) { for k, test := range tests { body := test.gfi.ToXML() - x := strings.ReplaceAll(string(body), "\n", ``) - y := strings.ReplaceAll(test.result, "\n", ``) + x := strings.Replace(string(body), "\n", ``, -1) + y := strings.Replace(test.result, "\n", ``, -1) if x != y { t.Errorf("test: %d, Expected body: \n%s\nbut was not got: \n%s", k, y, x) @@ -158,7 +157,6 @@ func TestGetFeatureInfoToXML(t *testing.T) { } } -//nolint:nestif func TestGetFeatureInfoParseQueryParameters(t *testing.T) { var tests = []struct { query url.Values @@ -235,8 +233,8 @@ func TestGetFeatureInfoParseQueryParameters(t *testing.T) { } else { for _, exception := range exceptions { found := false - for _, testException := range test.exceptions { - if errors.Is(testException, exception) { + for _, testexception := range test.exceptions { + if testexception == exception { found = true } } @@ -339,7 +337,6 @@ func TestGetFeatureInfoParseXML(t *testing.T) { } } -//nolint:cyclop func compareGetFeatureInfoObject(result, expected GetFeatureInfoRequest, t *testing.T, k int) { if result.BaseRequest.Version != expected.BaseRequest.Version { t.Errorf("test Version: %d, expected: %s ,\n got: %s", k, expected.Version, result.Version) diff --git a/pkg/wms130/getmap_request.go b/pkg/wms130/getmap_request.go index e121d92..a8326a9 100644 --- a/pkg/wms130/getmap_request.go +++ b/pkg/wms130/getmap_request.go @@ -117,9 +117,7 @@ func (m *GetMapRequest) ParseXML(body []byte) Exceptions { if err := xml.Unmarshal(body, &xmlattributes); err != nil { return Exceptions{MissingParameterValue()} } - // When object can be Unmarshalled -> XMLAttributes, it can be Unmarshalled -> GetMap - _ = xml.Unmarshal(body, &m) - + xml.Unmarshal(body, &m) //When object can be Unmarshalled -> XMLAttributes, it can be Unmarshalled -> GetMap var n []xml.Attr for _, a := range xmlattributes { switch strings.ToUpper(a.Name.Local) { @@ -309,29 +307,29 @@ func buildStyledLayerDescriptor(layers, styles []string) (StyledLayerDescriptor, // That is because POST xml and GET Parameter Value request handle this 'different' (at least not in the same way...) // When 3 is hit the validation at the Validation step wil resolve this - switch { // 1. - case len(styles) == 0: + if len(styles) == 0 { var sld StyledLayerDescriptor for _, layer := range layers { sld.NamedLayer = append(sld.NamedLayer, NamedLayer{Name: layer}) } sld.Version = "1.1.0" return sld, nil - // 2. - case len(layers) == 0: + // 2. + } else if len(layers) == 0 { // do nothing // will be resolved during validation - // 3. - case len(layers) == len(styles): + + // 3. + } else if len(layers) == len(styles) { var sld StyledLayerDescriptor for k, layer := range layers { sld.NamedLayer = append(sld.NamedLayer, NamedLayer{Name: layer, NamedStyle: &NamedStyle{Name: styles[k]}}) } sld.Version = "1.1.0" return sld, nil - // 4. - case len(layers) != len(styles): + // 4. + } else if len(layers) != len(styles) { return StyledLayerDescriptor{}, StyleNotDefined().ToExceptions() } diff --git a/pkg/wms130/getmap_request_pv.go b/pkg/wms130/getmap_request_pv.go index 054138e..ef9d71b 100644 --- a/pkg/wms130/getmap_request_pv.go +++ b/pkg/wms130/getmap_request_pv.go @@ -6,7 +6,7 @@ import ( "strings" ) -// getMapRequestParameterValue struct +//getMapRequestParameterValue struct type getMapRequestParameterValue struct { // Table 8 - The Parameters of a GetMap request service string `yaml:"service,omitempty"` @@ -16,8 +16,6 @@ type getMapRequestParameterValue struct { } // parseQueryParameters builds a getMapRequestParameterValue object based on the available query parameters -// -//nolint:cyclop,staticcheck func (mpv *getMapRequestParameterValue) parseQueryParameters(query url.Values) Exceptions { var exceptions Exceptions params := make(map[string]bool) @@ -91,7 +89,7 @@ func (mpv *getMapRequestParameterValue) parseQueryParameters(query url.Values) E } // parseGetMapRequest builds a getMapRequestParameterValue object based on a GetMap struct -func (mpv *getMapRequestParameterValue) parseGetMapRequest(m GetMapRequest) { +func (mpv *getMapRequestParameterValue) parseGetMapRequest(m GetMapRequest) Exceptions { mpv.request = getmap mpv.version = Version @@ -119,6 +117,8 @@ func (mpv *getMapRequestParameterValue) parseGetMapRequest(m GetMapRequest) { // mpv.Elevation = m.Elevation mpv.exceptions = m.Exceptions + + return nil } // BuildOutput builds a Output struct from the getMapRequestParameterValue information @@ -137,7 +137,7 @@ func (mpv *getMapRequestParameterValue) buildOutput() (Output, Exceptions) { output.Size = Size{Height: h, Width: w} output.Format = mpv.format if mpv.transparent != nil { - b, err := strconv.ParseBool(*mpv.transparent) + b, err := strconv.ParseBool(*mpv.transparent); if err != nil { return output, InvalidParameterValue(*mpv.transparent, TRANSPARENT).ToExceptions() } diff --git a/pkg/wms130/getmap_test.go b/pkg/wms130/getmap_test.go index 427c95a..a7e290e 100644 --- a/pkg/wms130/getmap_test.go +++ b/pkg/wms130/getmap_test.go @@ -87,7 +87,7 @@ func TestValidateStyledLayerDescriptor(t *testing.T) { } } if !found { - t.Errorf("test Exception: %d, expected one of: %s ,\n got: %s", k, test.exceptions, exception.Error()) + t.Errorf("test exception: %d, expected one of: %s ,\n got: %s", k, test.exceptions, exception.Error()) } } } @@ -98,7 +98,7 @@ func TestGetMapParseXML(t *testing.T) { var tests = []struct { body []byte excepted GetMapRequest - exception Exception + exception exception }{ // GetMap http://schemas.opengis.net/sld/1.1.0/example_getmap.xml example request 0: {body: []byte(`