From 2dfc355f7ca9e542feada27b75e41ef0daf719a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Sun, 3 Aug 2025 16:06:59 -0700 Subject: [PATCH] style: format Go code with gofumpt Apply consistent formatting to Go source files using gofumpt as required by pre-commit guidelines. --- chdb/chdnsanswers.go | 3 ++- chdb/logscores.go | 24 +++++++++++++----------- cmd/root.go | 4 +--- cmd/servercmd.go | 3 +-- logscores/history.go | 1 - ntpdb/dynamic_connect.go | 1 - ntpdb/models.go | 1 - server/dnsanswers.go | 7 ++++--- server/zones.go | 2 -- 9 files changed, 21 insertions(+), 25 deletions(-) diff --git a/chdb/chdnsanswers.go b/chdb/chdnsanswers.go index 4c18e1a..2175369 100644 --- a/chdb/chdnsanswers.go +++ b/chdb/chdnsanswers.go @@ -24,15 +24,16 @@ type ServerTotals map[string]uint64 func (s ServerQueries) Len() int { return len(s) } + func (s ServerQueries) Swap(i, j int) { s[i], s[j] = s[j], s[i] } + func (s ServerQueries) Less(i, j int) bool { return s[i].Count > s[j].Count } func (d *ClickHouse) ServerAnswerCounts(ctx context.Context, serverIP string, days int) (ServerQueries, error) { - ctx, span := tracing.Tracer().Start(ctx, "ServerAnswerCounts") defer span.End() diff --git a/chdb/logscores.go b/chdb/logscores.go index a2cf3ae..8246d9b 100644 --- a/chdb/logscores.go +++ b/chdb/logscores.go @@ -114,7 +114,7 @@ func (d *ClickHouse) LogscoresTimeRange(ctx context.Context, serverID, monitorID defer span.End() args := []interface{}{serverID, from, to} - + query := `select id,monitor_id,server_id,ts, toFloat64(score),toFloat64(step),offset, rtt,leap,warning,error @@ -131,15 +131,15 @@ func (d *ClickHouse) LogscoresTimeRange(ctx context.Context, serverID, monitorID // Always order by timestamp ASC for Grafana convention query += " order by ts ASC" - + // Apply limit to prevent memory issues if limit > 0 { query += " limit ?" args = append(args, limit) } - log.DebugContext(ctx, "clickhouse time range query", - "query", query, + log.DebugContext(ctx, "clickhouse time range query", + "query", query, "args", args, "server_id", serverID, "monitor_id", monitorID, @@ -205,7 +205,7 @@ func (d *ClickHouse) LogscoresTimeRange(ctx context.Context, serverID, monitorID rv = append(rv, row) } - log.InfoContext(ctx, "time range query results", + log.InfoContext(ctx, "time range query results", "rows_returned", len(rv), "server_id", serverID, "monitor_id", monitorID, @@ -214,13 +214,15 @@ func (d *ClickHouse) LogscoresTimeRange(ctx context.Context, serverID, monitorID "sample_rows", func() []map[string]interface{} { samples := make([]map[string]interface{}, 0, 3) for i, row := range rv { - if i >= 3 { break } + if i >= 3 { + break + } samples = append(samples, map[string]interface{}{ - "id": row.ID, - "monitor_id": row.MonitorID, - "ts": row.Ts.Format(time.RFC3339), - "score": row.Score, - "rtt_valid": row.Rtt.Valid, + "id": row.ID, + "monitor_id": row.MonitorID, + "ts": row.Ts.Format(time.RFC3339), + "score": row.Score, + "rtt_valid": row.Rtt.Valid, "offset_valid": row.Offset.Valid, }) } diff --git a/cmd/root.go b/cmd/root.go index 0b313de..da6426c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -30,7 +30,7 @@ func NewCLI() *CLI { // RootCmd represents the base command when called without any subcommands func (cli *CLI) rootCmd() *cobra.Command { - var cmd = &cobra.Command{ + cmd := &cobra.Command{ Use: "data-api", Short: "A brief description of your application", // Uncomment the following line if your bare application @@ -47,7 +47,6 @@ func (cli *CLI) rootCmd() *cobra.Command { // Execute adds all child commands to the root command and sets flags appropriately. // This is called by main.main(). It only needs to happen once to the rootCmd. func Execute() { - cli := NewCLI() if err := cli.root.Execute(); err != nil { @@ -57,7 +56,6 @@ func Execute() { } func (cli *CLI) init(cmd *cobra.Command) { - logger.Setup() cmd.PersistentFlags().StringVar(&cfgFile, "database-config", "database.yaml", "config file (default is $HOME/.data-api.yaml)") diff --git a/cmd/servercmd.go b/cmd/servercmd.go index 2892273..f67cc78 100644 --- a/cmd/servercmd.go +++ b/cmd/servercmd.go @@ -18,8 +18,7 @@ import ( ) func (cli *CLI) serverCmd() *cobra.Command { - - var serverCmd = &cobra.Command{ + serverCmd := &cobra.Command{ Use: "server", Short: "server starts the API server", Long: `starts the API server on (default) port 8000`, diff --git a/logscores/history.go b/logscores/history.go index 6197547..6fdbb9e 100644 --- a/logscores/history.go +++ b/logscores/history.go @@ -33,7 +33,6 @@ func GetHistoryClickHouse(ctx context.Context, ch *chdb.ClickHouse, db *sql.DB, log.DebugContext(ctx, "GetHistoryCH", "server", serverID, "monitor", monitorID, "since", since, "count", count, "full_history", fullHistory) ls, err := ch.Logscores(ctx, int(serverID), int(monitorID), since, count, fullHistory) - if err != nil { log.ErrorContext(ctx, "clickhouse logscores", "err", err) return nil, err diff --git a/ntpdb/dynamic_connect.go b/ntpdb/dynamic_connect.go index 2e47c21..4a15539 100644 --- a/ntpdb/dynamic_connect.go +++ b/ntpdb/dynamic_connect.go @@ -21,7 +21,6 @@ func (d Driver) Driver() driver.Driver { func (d Driver) Connect(ctx context.Context) (driver.Conn, error) { connector, err := d.CreateConnectorFunc() - if err != nil { return nil, fmt.Errorf("error creating connector from function: %w", err) } diff --git a/ntpdb/models.go b/ntpdb/models.go index 7292a97..44d639f 100644 --- a/ntpdb/models.go +++ b/ntpdb/models.go @@ -145,7 +145,6 @@ func (ns NullMonitorsType) Value() (driver.Value, error) { type ServerScoresStatus string const ( - ServerScoresStatusNew ServerScoresStatus = "new" ServerScoresStatusCandidate ServerScoresStatus = "candidate" ServerScoresStatusTesting ServerScoresStatus = "testing" ServerScoresStatusActive ServerScoresStatus = "active" diff --git a/server/dnsanswers.go b/server/dnsanswers.go index 656cb43..ec26193 100644 --- a/server/dnsanswers.go +++ b/server/dnsanswers.go @@ -16,8 +16,10 @@ import ( "go.ntppool.org/data-api/ntpdb" ) -const pointBasis float64 = 10000 -const pointSymbol = "‱" +const ( + pointBasis float64 = 10000 + pointSymbol = "‱" +) // const pointBasis = 1000 // const pointSymbol = "‰" @@ -163,5 +165,4 @@ func (srv *Server) dnsAnswers(c echo.Context) error { c.Response().Header().Set("Cache-Control", "public,max-age=1800") return c.JSONPretty(http.StatusOK, r, "") - } diff --git a/server/zones.go b/server/zones.go index bcce3e8..af17063 100644 --- a/server/zones.go +++ b/server/zones.go @@ -84,7 +84,6 @@ func (srv *Server) zoneCounts(c echo.Context) error { } else { // skip everything and use the special logic that we always include the most recent date skipCount = float64(count) + 1 - } } @@ -144,5 +143,4 @@ func (srv *Server) zoneCounts(c echo.Context) error { c.Response().Header().Set("Cache-Control", "s-maxage=28800, max-age=7200") return c.JSON(http.StatusOK, rv) - }