Skip to content

Commit

Permalink
Make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
corny committed Mar 28, 2022
1 parent 61d159f commit ff42378
Show file tree
Hide file tree
Showing 26 changed files with 46 additions and 59 deletions.
4 changes: 1 addition & 3 deletions database/graphite/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ func (c Config) Prefix() string {
}

func Connect(configuration map[string]interface{}) (database.Connection, error) {
var config Config

config = configuration
config := Config(configuration)

con := &Connection{
client: graphigo.Client{
Expand Down
2 changes: 1 addition & 1 deletion database/graphite/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"regexp"
)

var reInvalidChars = regexp.MustCompile("(?i)[^a-z0-9\\-]")
var reInvalidChars = regexp.MustCompile(`(?i)[^a-z0-9\\-]`)

func replaceInvalidChars(name string) string {
return reInvalidChars.ReplaceAllString(name, "_")
Expand Down
5 changes: 2 additions & 3 deletions database/influxdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/bdlm/log"
"github.com/influxdata/influxdb1-client/models"
"github.com/influxdata/influxdb1-client/v2"
client "github.com/influxdata/influxdb1-client/v2"

"github.com/FreifunkBremen/yanic/database"
)
Expand Down Expand Up @@ -62,8 +62,7 @@ func init() {
database.RegisterAdapter("influxdb", Connect)
}
func Connect(configuration map[string]interface{}) (database.Connection, error) {
var config Config
config = configuration
config := Config(configuration)

// Make client
c, err := client.NewHTTPClient(client.HTTPConfig{
Expand Down
7 changes: 4 additions & 3 deletions database/influxdb/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package influxdb

import (
"fmt"
"log"
"strconv"
"time"

Expand All @@ -15,7 +16,9 @@ import (
func (conn *Connection) PruneNodes(deleteAfter time.Duration) {
for _, measurement := range []string{MeasurementNode, MeasurementLink} {
query := fmt.Sprintf("delete from %s where time < now() - %ds", measurement, deleteAfter/time.Second)
conn.client.Query(client.NewQuery(query, conn.config.Database(), "m"))
if _, err := conn.client.Query(client.NewQuery(query, conn.config.Database(), "m")); err != nil {
log.Println(err)
}
}

}
Expand Down Expand Up @@ -197,6 +200,4 @@ func (conn *Connection) InsertNode(node *runtime.Node) {

conn.addPoint(MeasurementDHCP, tags, fields, time)
}

return
}
10 changes: 6 additions & 4 deletions database/logging/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package logging
*/
import (
"fmt"
"log"
"os"
"time"

Expand All @@ -31,8 +32,7 @@ func init() {
}

func Connect(configuration map[string]interface{}) (database.Connection, error) {
var config Config
config = configuration
config := Config(configuration)

file, err := os.OpenFile(config.Path(), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
if err != nil {
Expand Down Expand Up @@ -63,6 +63,8 @@ func (conn *Connection) Close() {
}

func (conn *Connection) log(v ...interface{}) {
fmt.Println(v...)
conn.file.WriteString(fmt.Sprintln("[", time.Now().String(), "]", v))
_, err := fmt.Fprintf(conn.file, "[%s] %v", time.Now().String(), v)
if err != nil {
log.Println(err)
}
}
3 changes: 1 addition & 2 deletions database/respondd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func init() {
}

func Connect(configuration map[string]interface{}) (database.Connection, error) {
var config Config
config = configuration
config := Config(configuration)

conn, err := net.Dial(config.Type(), config.Address())
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions output/filter/blocklist/blocklist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ func TestFilterBlocklist(t *testing.T) {
// invalid config
filter, err := build(3)
assert.Error(err)
assert.Nil(filter)

filter, err = build([]interface{}{2, "a"})
assert.Error(err)
assert.Nil(filter)

// tests with empty list
filter, err = build([]interface{}{})
Expand Down
5 changes: 3 additions & 2 deletions output/filter/domainappendsite/domainappendsite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ func TestFilter(t *testing.T) {
assert := assert.New(t)

// invalid config
filter, err := build("nope")
_, err := build("nope")
assert.Error(err)

// delete owner by configuration
filter, _ = build(true)
filter, err := build(true)
assert.NoError(err)
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
System: data.System{
SiteCode: "ffhb",
Expand Down
5 changes: 3 additions & 2 deletions output/filter/domainassite/domainassite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ func TestFilter(t *testing.T) {
assert := assert.New(t)

// invalid config
filter, err := build("nope")
_, err := build("nope")
assert.Error(err)

// delete owner by configuration
filter, _ = build(true)
filter, err := build(true)
assert.NoError(err)
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
System: data.System{
SiteCode: "ffhb",
Expand Down
2 changes: 1 addition & 1 deletion output/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func New(configs map[string]interface{}) (set Set, errs []error) {
return
}

f, _ := filters[name]
f := filters[name]
if f == nil {
errs = append(errs, fmt.Errorf("unknown filter: %s", name))
} else if filter, err := f(config); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions output/filter/haslocation/haslocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ func TestFilterHasLocation(t *testing.T) {
assert := assert.New(t)

// invalid config
filter, err := build(3)
_, err := build(3)
assert.Error(err)

// test to drop nodes without location
filter, err = build(true)
filter, err := build(true)
assert.NoError(err)

// node has location (with 0,0) -> keep it
Expand Down
5 changes: 3 additions & 2 deletions output/filter/noowner/noowner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ func TestFilter(t *testing.T) {
assert := assert.New(t)

// invalid config
filter, err := build("nope")
_, err := build("nope")
assert.Error(err)

// delete owner by configuration
filter, _ = build(true)
filter, err := build(true)
assert.NoError(err)
n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
Owner: &data.Owner{
Contact: "blub",
Expand Down
6 changes: 3 additions & 3 deletions output/filter/site/site_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ func TestFilterSite(t *testing.T) {
assert := assert.New(t)

// invalid config
filter, err := build("ffhb")
_, err := build("ffhb")
assert.Error(err)

filter, err = build([]interface{}{3, "ffhb"})
_, err = build([]interface{}{3, "ffhb"})
assert.Error(err)

filter, err = build([]interface{}{"ffhb"})
filter, err := build([]interface{}{"ffhb"})
assert.NoError(err)

// wronge node
Expand Down
7 changes: 1 addition & 6 deletions output/geojson/geojson_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import (
"github.com/FreifunkBremen/yanic/runtime"
)

const (
testNodeDescription string = "Online\nClients: 42\nModel: TP-Link 841\n" +
"Site: mysite\nDomain: domain_42\n"
)

func TestTransform(t *testing.T) {
testNodes := createTestNodes()
nodes := transform(testNodes)
Expand Down Expand Up @@ -41,7 +36,7 @@ func TestTransform(t *testing.T) {
nodePoint.Properties["clients"],
)
assert.Equal(
testNodeDescription,
"Online\nClients: 42\nModel: TP-Link 841\nSite: mysite\nDomain: domain_42\n",
nodePoint.Properties["description"],
)
}
Expand Down
3 changes: 1 addition & 2 deletions output/geojson/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func init() {
}

func Register(configuration map[string]interface{}) (output.Output, error) {
var config Config
config = configuration
config := Config(configuration)

if path := config.Path(); path != "" {
return &Output{
Expand Down
3 changes: 0 additions & 3 deletions output/meshviewer-ffrgb/meshviewer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ func TestTransform(t *testing.T) {
assert.Equal("node:b:mac:lan", link.TargetAddress)
assert.Equal(float32(0.2), link.SourceTQ)
assert.Equal(float32(0), link.TargetTQ)
break

case "node:a:mac:wifi":
assert.Equal("wifi", link.Type)
assert.Equal("node:b:mac:wifi", link.TargetAddress)
Expand All @@ -177,7 +175,6 @@ func TestTransform(t *testing.T) {
assert.Equal("node:c:mac:lan", link.TargetAddress)
assert.Equal(float32(0.8), link.SourceTQ)
assert.Equal(float32(0.4), link.TargetTQ)
break
default:
assert.False(true, "invalid link.SourceAddress found")
}
Expand Down
3 changes: 1 addition & 2 deletions output/meshviewer-ffrgb/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func init() {
}

func Register(configuration map[string]interface{}) (output.Output, error) {
var config Config
config = configuration
config := Config(configuration)

if path := config.Path(); path != "" {
return &Output{
Expand Down
3 changes: 1 addition & 2 deletions output/meshviewer/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func init() {
}

func Register(configuration map[string]interface{}) (output.Output, error) {
var config Config
config = configuration
config := Config(configuration)

builder := nodeFormats[config.Version()]
if builder == nil {
Expand Down
3 changes: 1 addition & 2 deletions output/nodelist/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func init() {
}

func Register(configuration map[string]interface{}) (output.Output, error) {
var config Config
config = configuration
config := Config(configuration)

if path := config.Path(); path != "" {
return &Output{
Expand Down
3 changes: 1 addition & 2 deletions output/raw-jsonl/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func init() {
}

func Register(configuration map[string]interface{}) (output.Output, error) {
var config Config
config = configuration
config := Config(configuration)

if path := config.Path(); path != "" {
return &Output{
Expand Down
5 changes: 0 additions & 5 deletions output/raw-jsonl/raw_jsonl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import (
"github.com/FreifunkBremen/yanic/runtime"
)

const (
testNodeDescription string = "Online\nClients: 42\nModel: TP-Link 841\n" +
"Site: mysite\nDomain: domain_42\n"
)

func TestTransform(t *testing.T) {
testNodes := createTestNodes()
result := transform(testNodes)
Expand Down
3 changes: 1 addition & 2 deletions output/raw/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func init() {
}

func Register(configuration map[string]interface{}) (output.Output, error) {
var config Config
config = configuration
config := Config(configuration)

if path := config.Path(); path != "" {
return &Output{
Expand Down
4 changes: 3 additions & 1 deletion respond/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ func (coll *Collector) listenUDP(iface InterfaceConfig) {
if err != nil {
log.Panic(err)
}
conn.SetReadBuffer(MaxDataGramSize)
if err := conn.SetReadBuffer(MaxDataGramSize); err != nil {
log.Println("failed to set read buffer:", err)
}

raw, err := conn.SyscallConn()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion rrd/rrd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/bdlm/log"
)

var linePattern = regexp.MustCompile("^<!-- ....-..-.. ..:..:.. [A-Z]+ / (\\d+) --> <row><v>([^<]+)</v><v>([^<]+)</v></row>")
var linePattern = regexp.MustCompile(`^<!-- ....-..-.. ..:..:.. [A-Z]+ / (\\d+) --> <row><v>([^<]+)</v><v>([^<]+)</v></row>`)

// Dataset a timestemp with values (node and clients)
type Dataset struct {
Expand Down
4 changes: 2 additions & 2 deletions runtime/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) *Node {
now := jsontime.Now()

nodes.Lock()
node, _ := nodes.List[nodeID]
node := nodes.List[nodeID]

if node == nil {
node = &Node{
Expand Down Expand Up @@ -213,7 +213,7 @@ func (nodes *Nodes) readIfaces(nodeinfo *data.Nodeinfo, warning bool) {
if addr == "" {
continue
}
if oldNodeID, _ := nodes.ifaceToNodeID[addr]; oldNodeID != nodeID {
if oldNodeID := nodes.ifaceToNodeID[addr]; oldNodeID != nodeID {
if oldNodeID != "" && warning {
log.Warnf("override nodeID from %s to %s on MAC address %s", oldNodeID, nodeID, addr)
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestSelectNodes(t *testing.T) {
})
assert.Len(selectedNodes, 1)
time := jsontime.Time{}
time.UnmarshalJSON([]byte("2017-03-10T12:12:01"))
assert.NoError(time.UnmarshalJSON([]byte("\"2017-03-10T12:12:01\"")))
assert.Equal(time, selectedNodes[0].Firstseen)
}

Expand Down

0 comments on commit ff42378

Please sign in to comment.