style: format Go code with gofumpt
Apply consistent formatting to Go source files using gofumpt as required by pre-commit guidelines.
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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)")
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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, "")
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user