Skip to content

Commit

Permalink
fixing golint ./... warnings & copyright year
Browse files Browse the repository at this point in the history
  • Loading branch information
d-led committed Jan 28, 2022
1 parent 3bc1788 commit d298e85
Show file tree
Hide file tree
Showing 31 changed files with 88 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .link-checker-service.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-2021 Siemens AG
# Copyright 2020-2022 Siemens AG
# This file is not subject to the MPLv2 license, and can be edited freely.

# proxy = "http://<some-proxy>:<port>"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ some URL check services exist, albeit not open source (as of 02.09.2020)
## License

```text
Copyright 2020-2021 Siemens AG and contributors as noted in the AUTHORS file.
Copyright 2020-2022 Siemens AG and contributors as noted in the AUTHORS file.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
Expand Down
3 changes: 2 additions & 1 deletion cmd/check.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package cmd

import (
Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package cmd

import (
Expand Down
3 changes: 2 additions & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package cmd

import (
Expand Down
3 changes: 2 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package cmd

import (
Expand Down
6 changes: 4 additions & 2 deletions infrastructure/cache.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import (
"encoding/json"
"time"

"github.com/dgraph-io/ristretto"
"github.com/patrickmn/go-cache"
"time"
)

type resultCache interface {
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/cached_url_checker.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import (
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/cc_limited_url_checker.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import (
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/domain_rate_limited_checker.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import (
Expand Down
42 changes: 22 additions & 20 deletions infrastructure/stats_collector.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import "sync"
Expand All @@ -12,7 +13,7 @@ type Stats struct {
IncomingRequests int64
OutgoingRequests int64
IncomingStreamRequests int64
DnsResolutionsFailed int64
DNSResolutionsFailed int64
LinkChecksErrored int64
LinkChecksOk int64
LinkChecksBroken int64
Expand All @@ -22,15 +23,16 @@ type Stats struct {
CacheMisses int64
}

type statsState struct {
// StatsState is the protected instance of the Stats object
type StatsState struct {
sync.RWMutex
s Stats
}

var globalStatsState = newStatsState()

// GlobalStats returns the global handler to the stats collector
func GlobalStats() *statsState {
func GlobalStats() *StatsState {
return globalStatsState
}

Expand All @@ -40,89 +42,89 @@ func ResetGlobalStats() {
}

// OnIncomingRequest call on incoming request
func (stats *statsState) OnIncomingRequest() {
func (stats *StatsState) OnIncomingRequest() {
stats.Lock()
stats.s.IncomingRequests++
stats.Unlock()
}

// OnIncomingStreamRequest called on an incoming stream request
func (stats *statsState) OnIncomingStreamRequest() {
func (stats *StatsState) OnIncomingStreamRequest() {
stats.Lock()
stats.s.IncomingStreamRequests++
stats.Unlock()
}

// OnOutgoingRequest called on outgoing request
func (stats *statsState) OnOutgoingRequest() {
func (stats *StatsState) OnOutgoingRequest() {
stats.Lock()
stats.s.OutgoingRequests++
stats.Unlock()
}

// OnDnsResolutionFailed called on dns resolution failure
func (stats *statsState) OnDnsResolutionFailed() {
// OnDNSResolutionFailed called on dns resolution failure
func (stats *StatsState) OnDNSResolutionFailed() {
stats.Lock()
stats.s.DnsResolutionsFailed++
stats.s.DNSResolutionsFailed++
stats.Unlock()
}

// OnLinkErrored called on link check error
func (stats *statsState) OnLinkErrored() {
func (stats *StatsState) OnLinkErrored() {
stats.Lock()
stats.s.LinkChecksErrored++
stats.Unlock()
}

// OnLinkOk called on link check ok
func (stats *statsState) OnLinkOk() {
func (stats *StatsState) OnLinkOk() {
stats.Lock()
stats.s.LinkChecksOk++
stats.Unlock()
}

// OnLinkBroken called on link check broken
func (stats *statsState) OnLinkBroken() {
func (stats *StatsState) OnLinkBroken() {
stats.Lock()
stats.s.LinkChecksBroken++
stats.Unlock()
}

// OnLinkDropped called on link check dropped
func (stats *statsState) OnLinkDropped() {
func (stats *StatsState) OnLinkDropped() {
stats.Lock()
stats.s.LinkChecksDropped++
stats.Unlock()
}

// OnLinkSkipped called on link check skipped
func (stats *statsState) OnLinkSkipped() {
func (stats *StatsState) OnLinkSkipped() {
stats.Lock()
stats.s.LinkChecksSkipped++
stats.Unlock()
}

// OnCacheHit called when the result is taken from the cache
func (stats *statsState) OnCacheHit() {
func (stats *StatsState) OnCacheHit() {
stats.Lock()
stats.s.CacheHits++
stats.Unlock()
}

// OnCacheMiss called when the requested URL wasn't found in the cache
func (stats *statsState) OnCacheMiss() {
func (stats *StatsState) OnCacheMiss() {
stats.Lock()
stats.s.CacheMisses++
stats.Unlock()
}

// GetStats returns a copy of the stats
func (stats *statsState) GetStats() Stats {
func (stats *StatsState) GetStats() Stats {
stats.RLock()
defer stats.RUnlock()
return stats.s // a copy
}

func newStatsState() *statsState {
return &statsState{}
func newStatsState() *StatsState {
return &StatsState{}
}
10 changes: 6 additions & 4 deletions infrastructure/stats_collector_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import (
"github.com/stretchr/testify/assert"
"sync"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCollectingFromSeveralGoroutines(t *testing.T) {
Expand All @@ -22,7 +24,7 @@ func TestCollectingFromSeveralGoroutines(t *testing.T) {
IncomingRequests: expectedCount,
OutgoingRequests: expectedCount,
IncomingStreamRequests: expectedCount,
DnsResolutionsFailed: expectedCount,
DNSResolutionsFailed: expectedCount,
LinkChecksErrored: expectedCount,
LinkChecksOk: expectedCount,
LinkChecksBroken: expectedCount,
Expand All @@ -47,7 +49,7 @@ func addStats(numGoroutines int, count int) {
s.OnIncomingStreamRequest()
s.OnLinkBroken()
s.OnLinkDropped()
s.OnDnsResolutionFailed()
s.OnDNSResolutionFailed()
s.OnLinkErrored()
s.OnLinkOk()
s.OnLinkSkipped()
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/strings.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import "strings"
Expand Down
6 changes: 4 additions & 2 deletions infrastructure/strings_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import (
"github.com/stretchr/testify/assert"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestSanitizingUserLogInputForNewlines(t *testing.T) {
Expand Down
7 changes: 4 additions & 3 deletions infrastructure/url_checker.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import (
Expand Down Expand Up @@ -455,7 +456,7 @@ func (c *URLCheckerClient) checkURL(ctx context.Context, urlToCheck string, clie
},
DNSDone: func(info httptrace.DNSDoneInfo) {
if remoteAddr == "" {
GlobalStats().OnDnsResolutionFailed()
GlobalStats().OnDNSResolutionFailed()
// this may not be as precise as ConnectDone, thus skipping caching
remoteAddr = getDNSAddressesAsString(info.Addrs)
}
Expand Down Expand Up @@ -529,7 +530,7 @@ func (c *URLCheckerClient) resolveAndCacheTCPAddr(network string, err error, add
remoteAddr = addr.String()
c.dnsCache.Set(addrToResolve, remoteAddr, defaultCacheExpirationInterval)
} else {
GlobalStats().OnDnsResolutionFailed()
GlobalStats().OnDNSResolutionFailed()
c.dnsCache.Set(addrToResolve, "DNS resolution failed", defaultRetryFailedAfter)
log.Printf("ERROR in resolveAndCacheTCPAddr: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/url_checker_plugin.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import "context"
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/url_checker_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import (
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/urlcheckstatus.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0
//go:generate go get github.com/alvaroloes/enumer
//go:generate enumer -type=URLCheckStatus -json -text -transform=lower

package infrastructure

//run go generate to generate enum serialization code
Expand Down
3 changes: 2 additions & 1 deletion infrastructure/version.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2020-2021 Siemens AG
// Copyright 2020-2022 Siemens AG
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
// SPDX-License-Identifier: MPL-2.0

package infrastructure

import "runtime/debug"
Expand Down
Loading

0 comments on commit d298e85

Please sign in to comment.