mirror of
https://github.com/safing/portbase
synced 2025-04-21 09:49:10 +00:00
Make linter happy
This commit is contained in:
parent
df62abdf1b
commit
ee9f722a9c
10 changed files with 21 additions and 14 deletions
|
@ -7,6 +7,7 @@ linters:
|
||||||
- containedctx
|
- containedctx
|
||||||
- contextcheck
|
- contextcheck
|
||||||
- cyclop
|
- cyclop
|
||||||
|
- depguard
|
||||||
- exhaustivestruct
|
- exhaustivestruct
|
||||||
- exhaustruct
|
- exhaustruct
|
||||||
- forbidigo
|
- forbidigo
|
||||||
|
@ -22,6 +23,7 @@ linters:
|
||||||
- interfacer
|
- interfacer
|
||||||
- ireturn
|
- ireturn
|
||||||
- lll
|
- lll
|
||||||
|
- musttag
|
||||||
- nestif
|
- nestif
|
||||||
- nilnil
|
- nilnil
|
||||||
- nlreturn
|
- nlreturn
|
||||||
|
|
|
@ -52,7 +52,7 @@ func init() {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
// DatabaseAPI is a database API instance.
|
// DatabaseAPI is a generic database API interface.
|
||||||
type DatabaseAPI struct {
|
type DatabaseAPI struct {
|
||||||
queriesLock sync.Mutex
|
queriesLock sync.Mutex
|
||||||
queries map[string]*iterator.Iterator
|
queries map[string]*iterator.Iterator
|
||||||
|
@ -67,6 +67,7 @@ type DatabaseAPI struct {
|
||||||
sendBytes func(data []byte)
|
sendBytes func(data []byte)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DatabaseWebsocketAPI is a database websocket API interface.
|
||||||
type DatabaseWebsocketAPI struct {
|
type DatabaseWebsocketAPI struct {
|
||||||
DatabaseAPI
|
DatabaseAPI
|
||||||
|
|
||||||
|
@ -78,6 +79,7 @@ func allowAnyOrigin(r *http.Request) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateDatabaseAPI creates a new database interface.
|
||||||
func CreateDatabaseAPI(sendFunction func(data []byte)) DatabaseAPI {
|
func CreateDatabaseAPI(sendFunction func(data []byte)) DatabaseAPI {
|
||||||
return DatabaseAPI{
|
return DatabaseAPI{
|
||||||
queries: make(map[string]*iterator.Iterator),
|
queries: make(map[string]*iterator.Iterator),
|
||||||
|
@ -195,6 +197,7 @@ func (api *DatabaseWebsocketAPI) shutdown(err error) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle handles a message for the database API.
|
||||||
func (api *DatabaseAPI) Handle(msg []byte) {
|
func (api *DatabaseAPI) Handle(msg []byte) {
|
||||||
// 123|get|<key>
|
// 123|get|<key>
|
||||||
// 123|ok|<key>|<data>
|
// 123|ok|<key>|<data>
|
||||||
|
@ -370,7 +373,7 @@ func (api *DatabaseAPI) processQuery(opID []byte, q *query.Query) (ok bool) {
|
||||||
case <-api.shutdownSignal:
|
case <-api.shutdownSignal:
|
||||||
// cancel query and return
|
// cancel query and return
|
||||||
it.Cancel()
|
it.Cancel()
|
||||||
return
|
return false
|
||||||
case r := <-it.Next:
|
case r := <-it.Next:
|
||||||
// process query feed
|
// process query feed
|
||||||
if r != nil {
|
if r != nil {
|
||||||
|
@ -656,7 +659,7 @@ func (api *DatabaseAPI) handleDelete(opID []byte, key string) {
|
||||||
api.send(opID, dbMsgTypeSuccess, emptyString, nil)
|
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.
|
// metadata and returning it as json.
|
||||||
func MarshalRecord(r record.Record, withDSDIdentifier bool) ([]byte, error) {
|
func MarshalRecord(r record.Record, withDSDIdentifier bool) ([]byte, error) {
|
||||||
r.Lock()
|
r.Lock()
|
||||||
|
|
|
@ -208,7 +208,7 @@ func getAPIContext(r *http.Request) (apiEndpoint *Endpoint, apiRequest *Request)
|
||||||
// does not pass the sanity checks.
|
// does not pass the sanity checks.
|
||||||
func RegisterEndpoint(e Endpoint) error {
|
func RegisterEndpoint(e Endpoint) error {
|
||||||
if err := e.check(); err != nil {
|
if err := e.check(); err != nil {
|
||||||
return fmt.Errorf("%w: %s", ErrInvalidEndpoint, err)
|
return fmt.Errorf("%w: %w", ErrInvalidEndpoint, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpointsLock.Lock()
|
endpointsLock.Lock()
|
||||||
|
@ -224,6 +224,7 @@ func RegisterEndpoint(e Endpoint) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetEndpointByPath returns the endpoint registered with the given path.
|
||||||
func GetEndpointByPath(path string) (*Endpoint, error) {
|
func GetEndpointByPath(path string) (*Endpoint, error) {
|
||||||
endpointsLock.Lock()
|
endpointsLock.Lock()
|
||||||
defer endpointsLock.Unlock()
|
defer endpointsLock.Unlock()
|
||||||
|
|
|
@ -33,6 +33,7 @@ type Request struct {
|
||||||
// apiRequestContextKey is a key used for the context key/value storage.
|
// apiRequestContextKey is a key used for the context key/value storage.
|
||||||
type apiRequestContextKey struct{}
|
type apiRequestContextKey struct{}
|
||||||
|
|
||||||
|
// RequestContextKey is the key used to add the API request to the context.
|
||||||
var RequestContextKey = apiRequestContextKey{}
|
var RequestContextKey = apiRequestContextKey{}
|
||||||
|
|
||||||
// GetAPIRequest returns the API Request of the given http request.
|
// GetAPIRequest returns the API Request of the given http request.
|
||||||
|
|
|
@ -45,7 +45,7 @@ func (i *Interface) DelayedCacheWriter(ctx context.Context) error {
|
||||||
i.flushWriteCache(0)
|
i.flushWriteCache(0)
|
||||||
|
|
||||||
case <-thresholdWriteTicker.C:
|
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
|
// flush it to storage before we start evicting to-be-written entries and
|
||||||
// slow down the hot path again.
|
// slow down the hot path again.
|
||||||
i.flushWriteCache(percentThreshold)
|
i.flushWriteCache(percentThreshold)
|
||||||
|
|
|
@ -62,7 +62,7 @@ func (s *Sinkhole) PutMany(shadowDelete bool) (chan<- record.Record, <-chan erro
|
||||||
// start handler
|
// start handler
|
||||||
go func() {
|
go func() {
|
||||||
for range batch {
|
for range batch {
|
||||||
// nom, nom, nom
|
// discard everything
|
||||||
}
|
}
|
||||||
errs <- nil
|
errs <- nil
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -30,7 +30,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Module represents a module.
|
// Module represents a module.
|
||||||
type Module struct {
|
type Module struct { //nolint:maligned
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
|
||||||
Name string
|
Name string
|
||||||
|
|
|
@ -44,7 +44,7 @@ func (f *Feeder) NeedsEntropy() bool {
|
||||||
return f.needsEntropy.IsSet()
|
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) {
|
func (f *Feeder) SupplyEntropy(data []byte, entropy int) {
|
||||||
f.input <- &entropyData{
|
f.input <- &entropyData{
|
||||||
data: data,
|
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) {
|
func (f *Feeder) SupplyEntropyIfNeeded(data []byte, entropy int) {
|
||||||
if f.needsEntropy.IsSet() {
|
if f.needsEntropy.IsSet() {
|
||||||
return
|
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) {
|
func (f *Feeder) SupplyEntropyAsInt(n int64, entropy int) {
|
||||||
b := make([]byte, 8)
|
b := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(b, uint64(n))
|
binary.LittleEndian.PutUint64(b, uint64(n))
|
||||||
f.SupplyEntropy(b, entropy)
|
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) {
|
func (f *Feeder) SupplyEntropyAsIntIfNeeded(n int64, entropy int) {
|
||||||
if f.needsEntropy.IsSet() { // avoid allocating a slice if possible
|
if f.needsEntropy.IsSet() { // avoid allocating a slice if possible
|
||||||
b := make([]byte, 8)
|
b := make([]byte, 8)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/safing/portbase/utils/renameio"
|
"github.com/safing/portbase/utils/renameio"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleTempFile_justone() {
|
func ExampleTempFile_justone() { //nolint:testableexamples
|
||||||
persist := func(temperature float64) error {
|
persist := func(temperature float64) error {
|
||||||
t, err := renameio.TempFile("", "/srv/www/metrics.txt")
|
t, err := renameio.TempFile("", "/srv/www/metrics.txt")
|
||||||
if err != nil {
|
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
|
// Prepare for writing files to /srv/www, effectively caching calls to
|
||||||
// TempDir which TempFile would otherwise need to make.
|
// TempDir which TempFile would otherwise need to make.
|
||||||
dir := renameio.TempDir("/srv/www")
|
dir := renameio.TempDir("/srv/www")
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// go:build !windows
|
//go:build !windows
|
||||||
|
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue