Skip to content

Commit

Permalink
Run gofumpt on codebase
Browse files Browse the repository at this point in the history
```
gofumpt -l -w .
```
  • Loading branch information
eest committed Oct 21, 2024
1 parent b0eb5c5 commit 3b41158
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 41 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ go tool pprof http://127.0.0.1:2112/debug/pprof/profile?seconds=30
When working with this code at least the following tools are expected to be
run at the top level directory prior to commiting:

* `go fmt ./...`
* `gofumpt -l -w .` (see [gofumpt](https://github.com/mvdan/gofumpt))
* `go vet ./...`
* `staticcheck ./...` (see [staticcheck](https://staticcheck.io))
* `gosec ./...` (see [gosec](https://github.com/securego/gosec))
Expand Down
8 changes: 5 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"github.com/spf13/viper"
)

var cfgFile string
var edmLogger *slog.Logger
var (
cfgFile string
edmLogger *slog.Logger
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -44,7 +46,7 @@ func init() {

// Cobra also supports local flags, which will only run
// when this action is called directly.
//rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

// initConfig reads in config file and ENV variables if set.
Expand Down
2 changes: 0 additions & 2 deletions pkg/runner/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

func (edm *dnstapMinimiser) newAutoPahoClientConfig(caCertPool *x509.CertPool, server string, clientID string, clientCert tls.Certificate, mqttKeepAlive uint16) (autopaho.ClientConfig, error) {

u, err := url.Parse(server)
if err != nil {
return autopaho.ClientConfig{}, fmt.Errorf("newAutoPahoClientConfig: unable to parse URL: %w", err)
Expand Down Expand Up @@ -46,7 +45,6 @@ func (edm *dnstapMinimiser) newAutoPahoClientConfig(caCertPool *x509.CertPool, s
}

return cliCfg, nil

}

func (edm *dnstapMinimiser) runAutoPaho(cm *autopaho.ConnectionManager, topic string, mqttJWK jwk.Key) {
Expand Down
17 changes: 3 additions & 14 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const dawgNotFound = -1
type edmStatusBits uint64

func (dsb *edmStatusBits) String() string {

if *dsb >= edmStatusMax {
return fmt.Sprintf("unknown flags in status: %b", *dsb)
}
Expand Down Expand Up @@ -275,7 +274,6 @@ func (edm *dnstapMinimiser) reverseLabelsBounded(labels []string, maxLen int) []

boundedReverseLabels = append(boundedReverseLabels, strings.Join(remainderLabels, "."))
}

}
return boundedReverseLabels
}
Expand Down Expand Up @@ -344,7 +342,6 @@ func getCryptopanAESKey(key string, salt string) []byte {
}

func (edm *dnstapMinimiser) setCryptopan(key string, salt string, cacheEntries int) error {

var cpnCache *lru.Cache[netip.Addr, netip.Addr]
var err error

Expand Down Expand Up @@ -719,7 +716,6 @@ func (edm *dnstapMinimiser) registerFSWatcher(filename string, callback func(str
}

func Run(logger *slog.Logger) {

if viper.GetBool("debug-enable-blockprofiling") {
logger.Info("enabling blocking profiling")
runtime.SetBlockProfileRate(int(time.Millisecond))
Expand Down Expand Up @@ -936,7 +932,7 @@ func Run(logger *slog.Logger) {
if debugDnstapFilename != "" {
// Make gosec happy
debugDnstapFilename := filepath.Clean(debugDnstapFilename)
debugDnstapFile, err = os.OpenFile(debugDnstapFilename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
debugDnstapFile, err = os.OpenFile(debugDnstapFilename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600)
if err != nil {
edm.log.Error("unable to open debug dnstap file", "error", err.Error(), "filename", debugDnstapFilename)
os.Exit(1)
Expand Down Expand Up @@ -1038,7 +1034,6 @@ type dnstapMinimiser struct {
}

func createCryptopan(key string, salt string) (*cryptopan.Cryptopan, error) {

cryptopanKey := getCryptopanAESKey(key, salt)

cpn, err := cryptopan.New(cryptopanKey)
Expand Down Expand Up @@ -1172,7 +1167,6 @@ type wellKnownDomainsData struct {
}

func newWellKnownDomainsTracker(dawgFinder dawg.Finder, dawgModTime time.Time) (*wellKnownDomainsTracker, error) {

return &wellKnownDomainsTracker{
wellKnownDomainsData: wellKnownDomainsData{
m: map[int]*histogramData{},
Expand Down Expand Up @@ -1225,7 +1219,6 @@ type wkdUpdate struct {
}

func (wkd *wellKnownDomainsTracker) lookup(msg *dns.Msg) (int, bool, time.Time) {

wkd.mutex.RLock()
defer wkd.mutex.RUnlock()

Expand Down Expand Up @@ -1266,7 +1259,6 @@ func (wkd *wellKnownDomainsTracker) updateRetryer(edm *dnstapMinimiser, wg *sync
}

func (wkd *wellKnownDomainsTracker) sendUpdate(ipBytes []byte, msg *dns.Msg, dawgIndex int, suffixMatch bool, dawgModTime time.Time) {

wu := wkdUpdate{
dawgIndex: dawgIndex,
suffixMatch: suffixMatch,
Expand Down Expand Up @@ -1319,7 +1311,6 @@ func (wkd *wellKnownDomainsTracker) sendUpdate(ipBytes []byte, msg *dns.Msg, daw
}

func (wkd *wellKnownDomainsTracker) rotateTracker(edm *dnstapMinimiser, dawgFile string, rotationTime time.Time) (*wellKnownDomainsData, error) {

dawgFileChanged := false
var dawgFinder dawg.Finder

Expand Down Expand Up @@ -1567,7 +1558,6 @@ minimiserLoop:
}

func (edm *dnstapMinimiser) monitorChannelLen() {

for {
edm.promNewQnameChannelLen.Set(float64(len(edm.newQnamePublisherCh)))
time.Sleep(time.Second * 1)
Expand Down Expand Up @@ -1708,7 +1698,7 @@ func (edm *dnstapMinimiser) renameFile(src string, dst string) error {
// If the destionation directory does not exist we will
// need to create it and then retry the Rename() in the
// next iteration of the loop.
err = os.MkdirAll(dstDir, 0750)
err = os.MkdirAll(dstDir, 0o750)
if err != nil {
return fmt.Errorf("renameFile: unable to create destination dir: %s: %w", dstDir, err)
}
Expand Down Expand Up @@ -1739,7 +1729,7 @@ func (edm *dnstapMinimiser) createFile(dst string) (*os.File, error) {
// If the destionation directory does not exist we will
// need to create it and then retry the file Create()
// the next iteration of the loop.
err = os.MkdirAll(dstDir, 0750)
err = os.MkdirAll(dstDir, 0o750)
if err != nil {
return nil, fmt.Errorf("createFile: unable to create destination dir: %s: %w", dstDir, err)
}
Expand Down Expand Up @@ -2025,7 +2015,6 @@ func getStartTimeFromRotationTime(rotationTime time.Time) time.Time {
}

func (edm *dnstapMinimiser) writeHistogramParquet(prevWellKnownDomainsData *wellKnownDomainsData, labelLimit int, outboxDir string) error {

if prevWellKnownDomainsData.dawgIsRotated {
defer func() {
err := prevWellKnownDomainsData.dawgFinder.Close()
Expand Down
32 changes: 11 additions & 21 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func BenchmarkSetHistogramLabels(b *testing.B) {
}

func TestWKD(t *testing.T) {

domainList := []string{
"example.com.", // exact match
".example.net.", // suffix match
Expand All @@ -86,7 +85,7 @@ func TestWKD(t *testing.T) {

dFinder := dBuilder.Finish()

var wkdDawgIndexTests = []struct {
wkdDawgIndexTests := []struct {
name string
domain string
found bool
Expand Down Expand Up @@ -171,7 +170,7 @@ func TestWKD(t *testing.T) {
t.Fatalf("unable to set HLL defaults: %s", err)
}

var wkdLookupTests = []struct {
wkdLookupTests := []struct {
name string
domain string
known bool
Expand Down Expand Up @@ -210,7 +209,6 @@ func TestWKD(t *testing.T) {
t.Fatalf("%s: unexpected known status, have: %t, want: %t", test.name, known, test.known)
}
}

}

func TestIgnoredClientIPsValid(t *testing.T) {
Expand Down Expand Up @@ -241,7 +239,7 @@ func TestIgnoredClientIPsValid(t *testing.T) {
t.Fatalf("unexpected number of CIDRs parsed from '%s': have: %d, want: %d", testdataFile1, numCIDRs, expectedNumCIDRs)
}

var ipLookupTests = []struct {
ipLookupTests := []struct {
name string
ip netip.Addr
ignored bool
Expand Down Expand Up @@ -322,7 +320,7 @@ func TestIgnoredClientIPsValid(t *testing.T) {
t.Fatalf("unexpected number of CIDRs parsed from '%s': have: %d, want: %d", testdataFile2, numCIDRs, expectedNumCIDRs)
}

var ipLookupTests2 = []struct {
ipLookupTests2 := []struct {
name string
ip netip.Addr
ignored bool
Expand Down Expand Up @@ -425,7 +423,7 @@ func TestIgnoredClientIPsEmptyLinesComments(t *testing.T) {
t.Fatalf("unexpected number of CIDRs parsed from '%s': have: %d, want: %d", testdataFile, numCIDRs, expectedNumCIDRs)
}

var ipLookupTests = []struct {
ipLookupTests := []struct {
name string
ip netip.Addr
ignored bool
Expand Down Expand Up @@ -513,7 +511,7 @@ func TestIgnoredClientIPsEmpty(t *testing.T) {
t.Fatalf("edm.ignoredClientsIPSet should be nil, have: %#v", edm.ignoredClientsIPSet)
}

var ipLookupTests = []struct {
ipLookupTests := []struct {
name string
ip netip.Addr
ignored bool
Expand Down Expand Up @@ -587,7 +585,7 @@ func TestIgnoredClientIPsUnset(t *testing.T) {
t.Fatalf("unexpected number of CIDRs parsed from '%s': have: %d, want: %d", "", numCIDRs, expectedNumCIDRs)
}

var ipLookupTests = []struct {
ipLookupTests := []struct {
name string
ip netip.Addr
ignored bool
Expand Down Expand Up @@ -703,7 +701,7 @@ func TestIgnoredQuestionNamesValid(t *testing.T) {
t.Fatalf("unexpected number of names parsed from '%s': have: %d, want: %d", testdataFile1, edm.ignoredQuestions.NumAdded(), expectedNumNames)
}

var questionLookupTests = []struct {
questionLookupTests := []struct {
name string
question string
ignored bool
Expand Down Expand Up @@ -770,7 +768,7 @@ func TestIgnoredQuestionNamesValid(t *testing.T) {
t.Fatalf("unexpected number of names parsed from '%s': have: %d, want: %d", testdataFile2, edm.ignoredQuestions.NumAdded(), expectedNumNames)
}

var questionLookupTests2 = []struct {
questionLookupTests2 := []struct {
name string
question string
ignored bool
Expand Down Expand Up @@ -866,7 +864,7 @@ func TestIgnoredQuestionNamesEmpty(t *testing.T) {

// Try to look for things that was present in the initial valid data
// that was loaded, none of it should be considered ignored now.
var questionLookupTests = []struct {
questionLookupTests := []struct {
name string
question string
ignored bool
Expand Down Expand Up @@ -948,7 +946,7 @@ func TestIgnoredQuestionNamesUnset(t *testing.T) {

// Try to look for things that was present in the initial valid data
// that was loaded, none of it should be considered ignored now.
var questionLookupTests = []struct {
questionLookupTests := []struct {
name string
question string
ignored bool
Expand Down Expand Up @@ -1132,7 +1130,6 @@ func TestSetSessionLabels(t *testing.T) {
}

func TestEDMStatusBitsMulti(t *testing.T) {

expectedString := "well-known-exact|well-known-wildcard"

dsb := new(edmStatusBits)
Expand All @@ -1145,7 +1142,6 @@ func TestEDMStatusBitsMulti(t *testing.T) {
}

func TestEDMStatusBitsSingle(t *testing.T) {

expectedString := "well-known-exact"

dsb := new(edmStatusBits)
Expand All @@ -1157,7 +1153,6 @@ func TestEDMStatusBitsSingle(t *testing.T) {
}

func TestEDMStatusBitsMax(t *testing.T) {

expectedString := "unknown flags in status"

dsb := new(edmStatusBits)
Expand All @@ -1169,7 +1164,6 @@ func TestEDMStatusBitsMax(t *testing.T) {
}

func TestEDMStatusBitsUnknown(t *testing.T) {

expectedString := "unknown flags in status"

dsb := new(edmStatusBits)
Expand All @@ -1181,7 +1175,6 @@ func TestEDMStatusBitsUnknown(t *testing.T) {
}

func TestEDMIPBytesToInt(t *testing.T) {

ipv4AddrString := "198.51.100.15"

ip4Addr, err := netip.ParseAddr(ipv4AddrString)
Expand Down Expand Up @@ -1209,7 +1202,6 @@ func TestEDMIPBytesToInt(t *testing.T) {
}

func TestEDMIP6BytesToInt(t *testing.T) {

ipv6AddrString := "2001:db8:1122:3344:5566:7788:99aa:bbcc"

ip6Addr, err := netip.ParseAddr(ipv6AddrString)
Expand Down Expand Up @@ -1558,7 +1550,6 @@ func TestPseudonymiseDnstap(t *testing.T) {
if uncachedPseudoRespAddr6 != expectedPseudoRespAddr6 {
t.Fatalf("uncached pseudonymised IPv6 resp address %s is not the expected address %s", uncachedPseudoRespAddr6, expectedPseudoRespAddr6)
}

}

func BenchmarkPseudonymiseDnstapWithCache4(b *testing.B) {
Expand Down Expand Up @@ -1718,7 +1709,6 @@ func BenchmarkMurmurSum64(b *testing.B) {
}

func TestCompareMurmurHashing(t *testing.T) {

murmur3Hasher := murmur3.New64()

ipAddrs := []string{"198.51.100.20", "198.51.100.21", "198.51.100.22"}
Expand Down

0 comments on commit 3b41158

Please sign in to comment.