Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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.12.1
131 changes: 131 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
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
path: _test\.go
- linters:
- cyclop
- goconst
- staticcheck
path: (.+)_test\.go
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/pdok/ogc-specifications

go 1.26
go 1.26.3

require gopkg.in/yaml.v3 v3.0.1
19 changes: 8 additions & 11 deletions pkg/utils/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,32 @@ 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
}

// 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 {
switch attr.Name.Local {
default:
newattributes = append(newattributes, xml.Attr{Name: attr.Name, Value: attr.Value})
}
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()
switch el := token.(type) {
case xml.EndElement:

if el, ok := token.(xml.EndElement); ok {
if el == start.End() {
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/wcs201/capabilities.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package wcs201

// ParseXML func
func (c *Capabilities) ParseXML(doc []byte) error {
func (c *Capabilities) ParseXML(_ []byte) error {
return nil
}

// ParseYAML func
func (c *Capabilities) ParseYAML(doc []byte) error {
func (c *Capabilities) ParseYAML(_ []byte) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/wcs201/getcapabilities_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (gc *GetCapabilitiesRequest) Type() string {
}

// Validate validates the GetCapabilities struct
func (gc *GetCapabilitiesRequest) Validate(c Capabilities) []wsc200.Exception {
func (gc *GetCapabilitiesRequest) Validate(_ Capabilities) []wsc200.Exception {
return nil
}

Expand Down
11 changes: 6 additions & 5 deletions pkg/wfs200/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ package wfs200

import (
"encoding/xml"

"github.com/pdok/ogc-specifications/pkg/wsc110"
)

// ParseXML func
func (c *Capabilities) ParseXML(doc []byte) error {
func (c *Capabilities) ParseXML(_ []byte) error {
return nil
}

// ParseYAML func
func (c *Capabilities) ParseYAML(doc []byte) error {
func (c *Capabilities) ParseYAML(_ []byte) error {
return nil
}

Expand Down Expand Up @@ -164,7 +165,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!!!
Expand All @@ -176,8 +177,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"`
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/wfs200/crs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 5 additions & 9 deletions pkg/wfs200/crs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ 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)
}
}
}
Expand All @@ -70,13 +68,11 @@ 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 {
stringCRS := string(yamlCRS)
if stringCRS != test.expectedYAML {
t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedYAML, stringCRS)
}
} else if stringCRS := string(yamlCRS); stringCRS != test.expectedYAML {
t.Errorf("test: %d, expected: %v+,\n got: %v+", k, test.expectedYAML, stringCRS)
}
}
}
7 changes: 2 additions & 5 deletions pkg/wfs200/crs_yaml.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package wfs200

// UnmarshalYAML CRS
//
//nolint:revive
func (c *CRS) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (c *CRS) UnmarshalYAML(unmarshal func(any) error) error {
var s string
if err := unmarshal(&s); err != nil {
return err
Expand All @@ -17,7 +15,6 @@ func (c *CRS) UnmarshalYAML(unmarshal func(interface{}) error) error {
return nil
}

//nolint:revive
func (c CRS) MarshalYAML() (interface{}, error) {
func (c CRS) MarshalYAML() (any, error) {
return c.String(), nil
}
6 changes: 3 additions & 3 deletions pkg/wfs200/describefeaturetype_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (d DescribeFeatureTypeRequest) Type() string {
}

// Validate returns GetCapabilities
func (d DescribeFeatureTypeRequest) Validate(c wsc110.Capabilities) []wsc110.Exception {
func (d DescribeFeatureTypeRequest) Validate(_ wsc110.Capabilities) []wsc110.Exception {
return nil
}

Expand Down Expand Up @@ -83,8 +83,8 @@ func (d *DescribeFeatureTypeRequest) parsedescribeFeatureTypeRequestParameterVal

d.TypeNames = dpv.typeName

if dpv.outputFormat != nil {
d.OutputFormat = dpv.outputFormat
if dpv.OutputFormat != nil {
d.OutputFormat = dpv.OutputFormat
} else {
s := gml32
d.OutputFormat = &(s)
Expand Down
Loading
Loading