Skip to content

Commit

Permalink
Run gofumpt -l -w . (#21)
Browse files Browse the repository at this point in the history
* Run gofumpt -l -w .

* Add in another set of strings that gofumpt missed
  • Loading branch information
eest authored Dec 14, 2024
1 parent eae16d4 commit c7b98f0
Show file tree
Hide file tree
Showing 21 changed files with 66 additions and 80 deletions.
1 change: 0 additions & 1 deletion api_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var pongs int = 0

func APIping(appName string, boottime time.Time) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {

tls := ""
if r.TLS != nil {
tls = "TLS "
Expand Down
6 changes: 2 additions & 4 deletions apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bytes"
"crypto/tls"
"encoding/json"

"fmt"
"io"
"log"
Expand Down Expand Up @@ -46,7 +45,7 @@ func (api *ApiClient) Setup() error {
api.Verbose = GlobalCF.Verbose
api.Debug = GlobalCF.Debug

var protocol = "http"
protocol := "http"

if api.BaseUrl == "" {
return fmt.Errorf("baseUrl not defined. Abort")
Expand Down Expand Up @@ -112,7 +111,7 @@ func (api *ApiClient) SetupTLS(tlsConfig *tls.Config) error {
api.Verbose = GlobalCF.Verbose
api.Debug = GlobalCF.Debug

var protocol = "https"
protocol := "https"

if api.BaseUrl == "" {
return fmt.Errorf("baseUrl not defined. Abort")
Expand Down Expand Up @@ -239,7 +238,6 @@ func (api *ApiClient) RequestNG(method, endpoint string, data interface{}, dieOn
}
// log.Printf("api.RequestNG: api: %+v req: %+v", api, req)
resp, err := api.HttpClient.Do(req)

if err != nil {
if api.Debug {
fmt.Printf("api.RequestNG: %s %s dieOnError: %v err: %v\n", method, endpoint, dieOnError, err)
Expand Down
6 changes: 4 additions & 2 deletions bitmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ const (
Frotz
)

var DefinedTags = []string{"newname", "highvolume", "badip", "cdntracker", "likelymalware", "likelybotnetcc",
var DefinedTags = []string{
"newname", "highvolume", "badip", "cdntracker", "likelymalware", "likelybotnetcc",
// "childporn",
"foo", "bar", "baz", "gazonk", "frotz"}
"foo", "bar", "baz", "gazonk", "frotz",
}

func SetTag(b, tag TagMask) TagMask { return b | tag }
func ClearTag(b, tag TagMask) TagMask { return b &^ tag }
Expand Down
1 change: 0 additions & 1 deletion certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func NewServerConfig(caFile string, clientAuth tls.ClientAuthType) (*tls.Config,
}

func NewClientConfig(caFile, keyFile, certFile string) (*tls.Config, error) {

caCertPool, err := loadCertPool(caFile)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package cmd
import (
"log"

"github.com/spf13/cobra"
"github.com/dnstapir/tapir"
"github.com/spf13/cobra"
)

var ApiCmd = &cobra.Command{
Expand Down
2 changes: 0 additions & 2 deletions cmd/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ var BumpCmd = &cobra.Command{
func init() {
BumpCmd.Flags().StringVarP(&tapir.GlobalCF.Zone, "zone", "z", "", "Zone name")
}


4 changes: 1 addition & 3 deletions cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var debugMqttStatsCmd = &cobra.Command{
fmt.Printf("%s\n", resp.Msg)
}

var out = []string{"MQTT Topic|Msgs|Last MQTT Message|Time since last msg"}
out := []string{"MQTT Topic|Msgs|Last MQTT Message|Time since last msg"}
for topic, count := range resp.MqttStats.MsgCounters {
t := resp.MqttStats.MsgTimeStamps[topic]
out = append(out, fmt.Sprintf("%s|%d|%s|%v\n", topic, count, t.Format(timelayout), time.Since(t).Round(time.Second)))
Expand Down Expand Up @@ -248,7 +248,6 @@ var debugGenerateSchemaCmd = &cobra.Command{
Use: "generate-schema",
Short: "Experimental: Generate the JSON schema for the current data structures",
Run: func(cmd *cobra.Command, args []string) {

reflector := &jsonschema.Reflector{
DoNotReference: true,
}
Expand All @@ -274,7 +273,6 @@ var debugImportGreylistCmd = &cobra.Command{
Use: "import-greylist",
Short: "Import the current data for the named greylist from the TEM bootstrap server",
Run: func(cmd *cobra.Command, args []string) {

if Listname == "" {
fmt.Printf("No greylist name specified, using 'dns-tapir'\n")
Listname = "dns-tapir"
Expand Down
5 changes: 2 additions & 3 deletions cmd/keyupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ package cmd
import (
"crypto/sha256"
"encoding/pem"
"path/filepath"

"fmt"
"log"
"os"
"path/filepath"
"time"

"github.com/dnstapir/tapir"
Expand All @@ -30,7 +29,7 @@ var KeyUploadCmd = &cobra.Command{
// log.Fatal("keyupload must have exactly one argument: the path to the public key file")
// }

var statusch = make(chan tapir.ComponentStatusUpdate, 10)
statusch := make(chan tapir.ComponentStatusUpdate, 10)

// If any status updates arrive, print them out
go func() {
Expand Down
43 changes: 19 additions & 24 deletions cmd/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import (
"bytes"
"crypto/ecdsa"
"encoding/json"
"net/http"
"path/filepath"
"regexp"

"fmt"
"io"
"log"
"net/http"
"os"
"os/signal"
"path/filepath"
"regexp"
"strings"
"sync"
"syscall"
Expand All @@ -33,10 +32,10 @@ import (
"gopkg.in/yaml.v3"
)

var mqttclientid, mqtttopic, defaulttopic, mqttgreylist, gcfgfile string

var mqttfid string
var mqttpub, mqttsub, mqttretain, mqttconfigclear bool
var (
mqttclientid, mqtttopic, defaulttopic, mqttgreylist, gcfgfile, mqttfid string
mqttpub, mqttsub, mqttretain, mqttconfigclear bool
)

var MqttCmd = &cobra.Command{
Use: "mqtt",
Expand All @@ -52,7 +51,7 @@ The engine can be configured to publish to and subscribe from the tapir config,
Run: func(cmd *cobra.Command, args []string) {
var wg sync.WaitGroup

var statusch = make(chan tapir.ComponentStatusUpdate, 10)
statusch := make(chan tapir.ComponentStatusUpdate, 10)

// If any status updates arrive, print them out
go func() {
Expand Down Expand Up @@ -81,8 +80,8 @@ The engine can be configured to publish to and subscribe from the tapir config,
os.Exit(1)
}

var canPub = true
var canSub = true
canPub := true
canSub := true
var signkey *ecdsa.PrivateKey
var valkey *ecdsa.PublicKey

Expand Down Expand Up @@ -274,8 +273,7 @@ var mqttTapirConfigCmd = &cobra.Command{
If -R is specified, will send a retained message, otherwise will send a normal message.
If -C is specified, will clear the retained config message, otherwise will send the new config.`,
Run: func(cmd *cobra.Command, args []string) {

var statusch = make(chan tapir.ComponentStatusUpdate, 10)
statusch := make(chan tapir.ComponentStatusUpdate, 10)

// If any status updates arrive, print them out
go func() {
Expand Down Expand Up @@ -387,8 +385,7 @@ var mqttTapirObservationsCmd = &cobra.Command{
Long: `Will query for operation (add|del|show|send|set-ttl|list-tags|quit), domain name and tags.
Will end the loop on the operation (or domain name) "QUIT"`,
Run: func(cmd *cobra.Command, args []string) {

var statusch = make(chan tapir.ComponentStatusUpdate, 10)
statusch := make(chan tapir.ComponentStatusUpdate, 10)

// If any status updates arrive, print them out
go func() {
Expand Down Expand Up @@ -439,7 +436,7 @@ Will end the loop on the operation (or domain name) "QUIT"`,
}

var op, names, tags string
var tmsg = tapir.TapirMsg{
tmsg := tapir.TapirMsg{
SrcName: srcname,
Creator: "tapir-cli",
MsgType: "observation",
Expand All @@ -450,7 +447,7 @@ Will end the loop on the operation (or domain name) "QUIT"`,
var snames []string
var tagmask tapir.TagMask

var ops = []string{"add", "del", "show", "send", "set-ttl", "list-tags", "quit"}
ops := []string{"add", "del", "show", "send", "set-ttl", "list-tags", "quit"}
fmt.Printf("Defined operations are: %v\n", ops)

var tds []tapir.Domain
Expand Down Expand Up @@ -513,7 +510,7 @@ Will end the loop on the operation (or domain name) "QUIT"`,
tds = []tapir.Domain{}

case "show":
var out = []string{"Domain|Tags"}
out := []string{"Domain|Tags"}
for _, td := range tmsg.Added {
out = append(out, fmt.Sprintf("ADD: %s|%032b", td.Name, td.TagMask))
}
Expand All @@ -523,7 +520,7 @@ Will end the loop on the operation (or domain name) "QUIT"`,
fmt.Println(columnize.SimpleFormat(out))

case "list-tags":
var out = []string{"Name|Bit"}
out := []string{"Name|Bit"}
var tagmask tapir.TagMask
for _, t := range tapir.DefinedTags {
tagmask, _ = tapir.StringsToTagMask([]string{t})
Expand Down Expand Up @@ -565,8 +562,7 @@ var mqttTapirStatusCmd = &cobra.Command{
Long: `Will query for operation (add|del|show|send|set-ttl|list-tags|quit), component name and status.
Will end the loop on the operation (or component name) "QUIT"`,
Run: func(cmd *cobra.Command, args []string) {

var statusch = make(chan tapir.ComponentStatusUpdate, 10)
statusch := make(chan tapir.ComponentStatusUpdate, 10)

// If any status updates arrive, print them out
go func() {
Expand Down Expand Up @@ -618,7 +614,7 @@ Will end the loop on the operation (or component name) "QUIT"`,
// TimeStamp: time.Now(),
// }

var ops = []string{"add", "del", "show", "send", "set-ttl", "list-tags", "quit"}
ops := []string{"add", "del", "show", "send", "set-ttl", "list-tags", "quit"}
fmt.Printf("Defined operations are: %v\n", ops)

tfs := tapir.TapirFunctionStatus{
Expand Down Expand Up @@ -700,7 +696,7 @@ Will end the loop on the operation (or component name) "QUIT"`,
tfs.ComponentStatus[cname] = comp

case "show":
var out = []string{"Component|Status|ErrorMsg|Msg|NumFailures|LastFailure|LastSuccess"}
out := []string{"Component|Status|ErrorMsg|Msg|NumFailures|LastFailure|LastSuccess"}
for cname, comp := range tfs.ComponentStatus {
out = append(out, fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s", cname, tapir.StatusToString[comp.Status], comp.ErrorMsg, comp.Msg, comp.NumFails,
comp.LastFail.Format(tapir.TimeLayout), comp.LastSuccess.Format(tapir.TimeLayout)))
Expand Down Expand Up @@ -1035,7 +1031,6 @@ func SetupInterruptHandler(cmnder chan tapir.MqttEngineCmd) {
go func() {
for {
select {

case <-ic:
fmt.Println("SIGTERM interrupt received, sending stop signal to MQTT Engine")
cmnder <- tapir.MqttEngineCmd{Cmd: "stop", Resp: respch}
Expand Down
4 changes: 2 additions & 2 deletions cmd/pop.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"fmt"
"log"
"net/http"
"time"
"time"

"github.com/dnstapir/tapir"
"github.com/ryanuber/columnize"
Expand Down Expand Up @@ -69,7 +69,7 @@ var PopStatusCmd = &cobra.Command{
if len(resp.TapirFunctionStatus.ComponentStatus) != 0 {
tfs := resp.TapirFunctionStatus
fmt.Printf("TAPIR-POP Status. Reported components: %d Total errors (since last start): %d\n", len(tfs.ComponentStatus), tfs.NumFailures)
var out = []string{"Component|Status|Error msg|# Fails|# Warns|LastFailure|LastSuccess"}
out := []string{"Component|Status|Error msg|# Fails|# Warns|LastFailure|LastSuccess"}
for k, v := range tfs.ComponentStatus {
out = append(out, fmt.Sprintf("%s|%s|%s|%d|%d|%v|%v", k, tapir.StatusToString[v.Status], v.ErrorMsg, v.NumFails, v.NumWarnings, v.LastFail.Format(tapir.TimeLayout), v.LastSuccess.Format(tapir.TimeLayout)))
}
Expand Down
1 change: 0 additions & 1 deletion cmd/rpz.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ var RpzListCmd = &cobra.Command{
Use: "list",
Short: "Instruct TAPIR-POP to remove a rule from the RPZ zone",
Run: func(cmd *cobra.Command, args []string) {

resp := SendCommandCmd(tapir.CommandPost{
Command: "rpz-list-sources",
})
Expand Down
3 changes: 1 addition & 2 deletions cmd/slogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func SloggerApi() (*tapir.ApiClient, error) {
return nil, fmt.Errorf("Error: missing config key: %s", urlkey)
}

api := &tapir.ApiClient{
api := &tapir.ApiClient{
BaseUrl: baseurl,
ApiKey: viper.GetString("cli." + servername + ".apikey"),
AuthMethod: "X-API-Key",
Expand Down Expand Up @@ -200,7 +200,6 @@ func SloggerApi() (*tapir.ApiClient, error) {
}

func SendSloggerCommand(data tapir.SloggerCmdPost) tapir.SloggerCmdResponse {

api, err := SloggerApi()
if err != nil {
log.Fatalf("Error: Could not set up API client to TAPIR-SLOGGER: %v", err)
Expand Down
10 changes: 6 additions & 4 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
*/
package tapir

const DefaultPopCfgFile = "/etc/dnstapir/tapir-pop.yaml"
const PopSourcesCfgFile = "/etc/dnstapir/pop-sources.yaml"
const PopOutputsCfgFile = "/etc/dnstapir/pop-outputs.yaml"
const PopPolicyCfgFile = "/etc/dnstapir/pop-policy.yaml"
const (
DefaultPopCfgFile = "/etc/dnstapir/tapir-pop.yaml"
PopSourcesCfgFile = "/etc/dnstapir/pop-sources.yaml"
PopOutputsCfgFile = "/etc/dnstapir/pop-outputs.yaml"
PopPolicyCfgFile = "/etc/dnstapir/pop-policy.yaml"
)

const DefaultTapirCliCfgFile = "/etc/dnstapir/tapir-cli.yaml"

Expand Down
3 changes: 2 additions & 1 deletion delegation_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
package tapir

import (
"github.com/miekg/dns"
"log"

"github.com/miekg/dns"
)

func (zd *ZoneData) FindGlue(nsrrs RRset) *RRset {
Expand Down
2 changes: 0 additions & 2 deletions dns_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const (
// TODO: Add support for TSIG zone transfers.

func (zd *ZoneData) ZoneTransferIn(upstream string, serial uint32, ttype string) (uint32, error) {

if upstream == "" {
log.Fatalf("ZoneTransfer: upstream not set")
}
Expand Down Expand Up @@ -110,7 +109,6 @@ func (zd *ZoneData) ReadZoneString(s string) (uint32, error) {
}

func (zd *ZoneData) ReadZone(r io.Reader) (uint32, error) {

switch zd.ZoneType {
case MapZone, SliceZone, RpzZone:
// zd.Data = make(map[string]map[uint16][]dns.RR, 30)
Expand Down
10 changes: 5 additions & 5 deletions globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ type CliFlags struct {
Api *ApiClient
PingCount int
Zone string
// TODO cleaner solution:
// Moved "certname" from slogger.go here so it can know what cert to look
// for. "certname" was previously declared globally in "root.go", but since
// the move to the tapir lib, slogger.go no longer sees that variable.
Certname string
// TODO cleaner solution:
// Moved "certname" from slogger.go here so it can know what cert to look
// for. "certname" was previously declared globally in "root.go", but since
// the move to the tapir lib, slogger.go no longer sees that variable.
Certname string
}

var GlobalCF CliFlags
1 change: 0 additions & 1 deletion logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
)

func SetupLogging(logfile string) error {

if logfile != "" {
log.SetOutput(&lumberjack.Logger{
Filename: logfile,
Expand Down
Loading

0 comments on commit c7b98f0

Please sign in to comment.