Make linter happy

This commit is contained in:
Daniel 2023-07-20 14:48:14 +02:00
parent df62abdf1b
commit ee9f722a9c
10 changed files with 21 additions and 14 deletions

View file

@ -7,6 +7,7 @@ linters:
- containedctx
- contextcheck
- cyclop
- depguard
- exhaustivestruct
- exhaustruct
- forbidigo
@ -22,6 +23,7 @@ linters:
- interfacer
- ireturn
- lll
- musttag
- nestif
- nilnil
- nlreturn

View file

@ -52,7 +52,7 @@ func init() {
))
}
// DatabaseAPI is a database API instance.
// DatabaseAPI is a generic database API interface.
type DatabaseAPI struct {
queriesLock sync.Mutex
queries map[string]*iterator.Iterator
@ -67,6 +67,7 @@ type DatabaseAPI struct {
sendBytes func(data []byte)
}
// DatabaseWebsocketAPI is a database websocket API interface.
type DatabaseWebsocketAPI struct {
DatabaseAPI
@ -78,6 +79,7 @@ func allowAnyOrigin(r *http.Request) bool {
return true
}
// CreateDatabaseAPI creates a new database interface.
func CreateDatabaseAPI(sendFunction func(data []byte)) DatabaseAPI {
return DatabaseAPI{
queries: make(map[string]*iterator.Iterator),
@ -195,6 +197,7 @@ func (api *DatabaseWebsocketAPI) shutdown(err error) error {
return nil
}
// Handle handles a message for the database API.
func (api *DatabaseAPI) Handle(msg []byte) {
// 123|get|<key>
// 123|ok|<key>|<data>
@ -370,7 +373,7 @@ func (api *DatabaseAPI) processQuery(opID []byte, q *query.Query) (ok bool) {
case <-api.shutdownSignal:
// cancel query and return
it.Cancel()
return
return false
case r := <-it.Next:
// process query feed
if r != nil {
@ -656,7 +659,7 @@ func (api *DatabaseAPI) handleDelete(opID []byte, key string) {
api.send(opID, dbMsgTypeSuccess, emptyString, nil)
}
// MarshalRecords locks and marshals the given record, additionally adding
// MarshalRecord locks and marshals the given record, additionally adding
// metadata and returning it as json.
func MarshalRecord(r record.Record, withDSDIdentifier bool) ([]byte, error) {
r.Lock()

View file

@ -208,7 +208,7 @@ func getAPIContext(r *http.Request) (apiEndpoint *Endpoint, apiRequest *Request)
// does not pass the sanity checks.
func RegisterEndpoint(e Endpoint) error {
if err := e.check(); err != nil {
return fmt.Errorf("%w: %s", ErrInvalidEndpoint, err)
return fmt.Errorf("%w: %w", ErrInvalidEndpoint, err)
}
endpointsLock.Lock()
@ -224,6 +224,7 @@ func RegisterEndpoint(e Endpoint) error {
return nil
}
// GetEndpointByPath returns the endpoint registered with the given path.
func GetEndpointByPath(path string) (*Endpoint, error) {
endpointsLock.Lock()
defer endpointsLock.Unlock()

View file

@ -33,6 +33,7 @@ type Request struct {
// apiRequestContextKey is a key used for the context key/value storage.
type apiRequestContextKey struct{}
// RequestContextKey is the key used to add the API request to the context.
var RequestContextKey = apiRequestContextKey{}
// GetAPIRequest returns the API Request of the given http request.

View file

@ -45,7 +45,7 @@ func (i *Interface) DelayedCacheWriter(ctx context.Context) error {
i.flushWriteCache(0)
case <-thresholdWriteTicker.C:
// Often check if the the write cache has filled up to a certain degree and
// Often check if the write cache has filled up to a certain degree and
// flush it to storage before we start evicting to-be-written entries and
// slow down the hot path again.
i.flushWriteCache(percentThreshold)

View file

@ -62,7 +62,7 @@ func (s *Sinkhole) PutMany(shadowDelete bool) (chan<- record.Record, <-chan erro
// start handler
go func() {
for range batch {
// nom, nom, nom
// discard everything
}
errs <- nil
}()

View file

@ -30,7 +30,7 @@ var (
)
// Module represents a module.
type Module struct {
type Module struct { //nolint:maligned
sync.RWMutex
Name string

View file

@ -44,7 +44,7 @@ func (f *Feeder) NeedsEntropy() bool {
return f.needsEntropy.IsSet()
}
// SupplyEntropy supplies entropy to to the Feeder, it will block until the Feeder has read from it.
// SupplyEntropy supplies entropy to the Feeder, it will block until the Feeder has read from it.
func (f *Feeder) SupplyEntropy(data []byte, entropy int) {
f.input <- &entropyData{
data: data,
@ -52,7 +52,7 @@ func (f *Feeder) SupplyEntropy(data []byte, entropy int) {
}
}
// SupplyEntropyIfNeeded supplies entropy to to the Feeder, but will not block if no entropy is currently needed.
// SupplyEntropyIfNeeded supplies entropy to the Feeder, but will not block if no entropy is currently needed.
func (f *Feeder) SupplyEntropyIfNeeded(data []byte, entropy int) {
if f.needsEntropy.IsSet() {
return
@ -67,14 +67,14 @@ func (f *Feeder) SupplyEntropyIfNeeded(data []byte, entropy int) {
}
}
// SupplyEntropyAsInt supplies entropy to to the Feeder, it will block until the Feeder has read from it.
// SupplyEntropyAsInt supplies entropy to the Feeder, it will block until the Feeder has read from it.
func (f *Feeder) SupplyEntropyAsInt(n int64, entropy int) {
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, uint64(n))
f.SupplyEntropy(b, entropy)
}
// SupplyEntropyAsIntIfNeeded supplies entropy to to the Feeder, but will not block if no entropy is currently needed.
// SupplyEntropyAsIntIfNeeded supplies entropy to the Feeder, but will not block if no entropy is currently needed.
func (f *Feeder) SupplyEntropyAsIntIfNeeded(n int64, entropy int) {
if f.needsEntropy.IsSet() { // avoid allocating a slice if possible
b := make([]byte, 8)

View file

@ -7,7 +7,7 @@ import (
"github.com/safing/portbase/utils/renameio"
)
func ExampleTempFile_justone() {
func ExampleTempFile_justone() { //nolint:testableexamples
persist := func(temperature float64) error {
t, err := renameio.TempFile("", "/srv/www/metrics.txt")
if err != nil {
@ -28,7 +28,7 @@ func ExampleTempFile_justone() {
}
}
func ExampleTempFile_many() {
func ExampleTempFile_many() { //nolint:testableexamples
// Prepare for writing files to /srv/www, effectively caching calls to
// TempDir which TempFile would otherwise need to make.
dir := renameio.TempDir("/srv/www")

View file

@ -1,4 +1,4 @@
// go:build !windows
//go:build !windows
package utils