Skip to content

chore: update golang to 1.24.1 #17035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
5df49f9
feat: update Go version to 1.24.1
Mar 21, 2025
83e79be
refactor: simplify Go 1.24.1 update
Mar 21, 2025
57a47e0
revert: simplify change to go version only
Mar 21, 2025
8187c9e
fix: update guts dependency to support Go 1.24.1
Mar 21, 2025
5aaf404
fix: update golangci-lint tool for Go 1.24.1
Mar 21, 2025
d7160ae
fix: temporarily disable Go linting due to Go 1.24.1 compatibility is…
Mar 21, 2025
3c3aa21
fix: update golangci-lint to v1.57.1 for Go 1.24.1 compatibility
Mar 21, 2025
4710808
fix: upgrade golangci-lint to v1.64.8
Mar 21, 2025
2bcb38a
revert: restore original lint/go implementation in Makefile
Mar 21, 2025
651d489
fix: restore original Makefile structure with continue-on-error for l…
Mar 21, 2025
77b2908
chore: remove continue-on-error behavior from lint/go
Mar 21, 2025
226e838
update golangci rules
sreya Mar 24, 2025
02fd64a
fix config
sreya Mar 24, 2025
3d07833
ignore unused parameters in tests
sreya Mar 25, 2025
75be2c3
update golangci rules
sreya Mar 25, 2025
2b19287
more updates
sreya Mar 25, 2025
ee44d98
fix: Add #nosec G115 annotations to address integer overflow conversi…
sreya Mar 25, 2025
f8af6a8
fix: Add more #nosec G115 annotations for integer overflow warnings
sreya Mar 25, 2025
3cf7102
fix: address G115 integer overflow linter warnings for Go 1.24.1
sreya Mar 25, 2025
527df65
fix: address more G115 integer overflow linter warnings
sreya Mar 25, 2025
7d11352
refactor: replace if-else chains with switch statements
sreya Mar 25, 2025
59e1b9c
fix: resolve unused parameter linter issues for Go 1.24.1 compatibility
sreya Mar 25, 2025
bb5aa17
fix: resolve unused-parameter warnings for Go 1.24.1 compatibility
sreya Mar 26, 2025
0b3571a
errname and fix changes
sreya Mar 26, 2025
7f93228
more fixes
sreya Mar 26, 2025
792b4b5
fix compilation error
sreya Mar 26, 2025
a4f441a
fix: resolve G115 integer overflow conversion warnings for Go 1.24.1 …
sreya Mar 26, 2025
5caf54d
fix: convert if-else chains to switch statements for Go 1.24.1 compat…
sreya Mar 26, 2025
d9b665c
fix abhorrent edits
sreya Mar 26, 2025
7e0ceec
fix more linting rules
sreya Mar 26, 2025
1530bfb
fix agent
sreya Mar 26, 2025
9ae5514
fix more stuff
sreya Mar 26, 2025
e2e1e17
fix test
sreya Mar 26, 2025
f3f5755
fix: resolve remaining redefines-builtin-id linting issues
sreya Mar 26, 2025
9b0a218
fix appendAssign
sreya Mar 26, 2025
d3581a8
fix: resolve deferUnlambda linting issues by simplifying defer statem…
sreya Mar 26, 2025
1bb7942
fix ifelse
sreya Mar 26, 2025
31311d3
fix assignOp linting errors
Mar 26, 2025
3b93057
Revert "fix: resolve deferUnlambda linting issues by simplifying defe…
sreya Mar 26, 2025
3a4ac1e
unlambda && make gen
sreya Mar 26, 2025
38de0cf
don't commit dbmock
sreya Mar 26, 2025
3afeb90
make gen
sreya Mar 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix ifelse
  • Loading branch information
sreya committed Mar 26, 2025
commit 1bb794243bd5019478e5e4d716aaafd24348e849
7 changes: 4 additions & 3 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -1623,11 +1623,12 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
wg.Wait()
sort.Float64s(durations)
durationsLength := len(durations)
if durationsLength == 0 {
switch {
case durationsLength == 0:
stats.ConnectionMedianLatencyMs = -1
} else if durationsLength%2 == 0 {
case durationsLength%2 == 0:
stats.ConnectionMedianLatencyMs = (durations[durationsLength/2-1] + durations[durationsLength/2]) / 2
} else {
default:
stats.ConnectionMedianLatencyMs = durations[durationsLength/2]
}
// Convert from microseconds to milliseconds.
Expand Down
7 changes: 4 additions & 3 deletions agent/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,22 @@ func (a *agent) collectMetrics(ctx context.Context) []*proto.Stats_Metric {
for _, metric := range metricFamily.GetMetric() {
labels := toAgentMetricLabels(metric.Label)

if metric.Counter != nil {
switch {
case metric.Counter != nil:
collected = append(collected, &proto.Stats_Metric{
Name: metricFamily.GetName(),
Type: proto.Stats_Metric_COUNTER,
Value: metric.Counter.GetValue(),
Labels: labels,
})
} else if metric.Gauge != nil {
case metric.Gauge != nil:
collected = append(collected, &proto.Stats_Metric{
Name: metricFamily.GetName(),
Type: proto.Stats_Metric_GAUGE,
Value: metric.Gauge.GetValue(),
Labels: labels,
})
} else {
default:
a.logger.Error(ctx, "unsupported metric type", slog.F("type", metricFamily.Type.String()))
}
}
Expand Down
6 changes: 3 additions & 3 deletions apiversion/apiversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"golang.org/x/xerrors"
)

// NewAPIVersion returns an *APIVersion with the given major.minor and
// New returns an *APIVersion with the given major.minor and
// additional supported major versions.
func NewAPIVersion(maj, min int) *APIVersion {
func New(maj, minor int) *APIVersion {
v := &APIVersion{
supportedMajor: maj,
supportedMinor: min,
supportedMinor: minor,
additionalMajors: make([]int, 0),
}
return v
Expand Down
2 changes: 1 addition & 1 deletion apiversion/apiversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestAPIVersionValidate(t *testing.T) {
t.Parallel()

// Given
v := apiversion.NewAPIVersion(2, 1).WithBackwardCompat(1)
v := apiversion.New(2, 1).WithBackwardCompat(1)

for _, tc := range []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion cli/cliutil/levenshtein/levenshtein.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ func minOf[T constraints.Ordered](ts ...T) T {
}
}
return m
}
}
4 changes: 2 additions & 2 deletions cmd/coder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
_ "time/tzdata"

_ "github.com/coder/coder/v2/buildinfo/resources"
"github.com/coder/coder/v2/cli"
)

func main() {
panic("hey")

// This preserves backwards compatibility with an init function that is causing grief for
// web terminals using agent-exec + screen. See https://github.com/coder/coder/pull/15817

var rootCmd cli.RootCmd
rootCmd.RunWithSubcommands(rootCmd.AGPL())
}
27 changes: 15 additions & 12 deletions coderd/database/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3072,21 +3072,22 @@ func TestGetUserStatusCounts(t *testing.T) {
row.Date.In(location).String(),
i,
)
if row.Date.Before(createdAt) {
switch {
case row.Date.Before(createdAt):
require.Equal(t, int64(0), row.Count)
} else if row.Date.Before(firstTransitionTime) {
case row.Date.Before(firstTransitionTime):
if row.Status == tc.initialStatus {
require.Equal(t, int64(1), row.Count)
} else if row.Status == tc.targetStatus {
require.Equal(t, int64(0), row.Count)
}
} else if !row.Date.After(today) {
case !row.Date.After(today):
if row.Status == tc.initialStatus {
require.Equal(t, int64(0), row.Count)
} else if row.Status == tc.targetStatus {
require.Equal(t, int64(1), row.Count)
}
} else {
default:
t.Errorf("date %q beyond expected range end %q", row.Date, today)
}
}
Expand Down Expand Up @@ -3227,18 +3228,19 @@ func TestGetUserStatusCounts(t *testing.T) {
expectedCounts[d][tc.user2Transition.to] = 0

// Counted Values
if d.Before(createdAt) {
switch {
case d.Before(createdAt):
continue
} else if d.Before(firstTransitionTime) {
case d.Before(firstTransitionTime):
expectedCounts[d][tc.user1Transition.from]++
expectedCounts[d][tc.user2Transition.from]++
} else if d.Before(secondTransitionTime) {
case d.Before(secondTransitionTime):
expectedCounts[d][tc.user1Transition.to]++
expectedCounts[d][tc.user2Transition.from]++
} else if d.Before(today) {
case d.Before(today):
expectedCounts[d][tc.user1Transition.to]++
expectedCounts[d][tc.user2Transition.to]++
} else {
default:
t.Fatalf("date %q beyond expected range end %q", d, today)
}
}
Expand Down Expand Up @@ -3331,11 +3333,12 @@ func TestGetUserStatusCounts(t *testing.T) {
i,
)
require.Equal(t, database.UserStatusActive, row.Status)
if row.Date.Before(createdAt) {
switch {
case row.Date.Before(createdAt):
require.Equal(t, int64(0), row.Count)
} else if i == len(userStatusChanges)-1 {
case i == len(userStatusChanges)-1:
require.Equal(t, int64(0), row.Count)
} else {
default:
require.Equal(t, int64(1), row.Count)
}
}
Expand Down
7 changes: 4 additions & 3 deletions coderd/userauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,8 @@ func (api *API) accessTokenClaims(ctx context.Context, rw http.ResponseWriter, s
func (api *API) userInfoClaims(ctx context.Context, rw http.ResponseWriter, state httpmw.OAuth2State, logger slog.Logger) (userInfoClaims map[string]interface{}, ok bool) {
userInfoClaims = make(map[string]interface{})
userInfo, err := api.OIDCConfig.Provider.UserInfo(ctx, oauth2.StaticTokenSource(state.Token))
if err == nil {
switch {
case err == nil:
err = userInfo.Claims(&userInfoClaims)
if err != nil {
logger.Error(ctx, "oauth2: unable to unmarshal user info claims", slog.Error(err))
Expand All @@ -1523,14 +1524,14 @@ func (api *API) userInfoClaims(ctx context.Context, rw http.ResponseWriter, stat
slog.F("claim_fields", claimFields(userInfoClaims)),
slog.F("blank", blankFields(userInfoClaims)),
)
} else if !strings.Contains(err.Error(), "user info endpoint is not supported by this provider") {
case !strings.Contains(err.Error(), "user info endpoint is not supported by this provider"):
logger.Error(ctx, "oauth2: unable to obtain user information claims", slog.Error(err))
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Failed to obtain user information claims.",
Detail: "The attempt to fetch claims via the UserInfo endpoint failed: " + err.Error(),
})
return nil, false
} else {
default:
// The OIDC provider does not support the UserInfo endpoint.
// This is not an error, but we should log it as it may mean
// that some claims are missing.
Expand Down
7 changes: 4 additions & 3 deletions coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -980,10 +980,11 @@ func (api *API) handleResumeToken(ctx context.Context, rw http.ResponseWriter, r
peerID, err = api.Options.CoordinatorResumeTokenProvider.VerifyResumeToken(ctx, resumeToken)
// If the token is missing the key ID, it's probably an old token in which
// case we just want to generate a new peer ID.
if xerrors.Is(err, jwtutils.ErrMissingKeyID) {
switch {
case xerrors.Is(err, jwtutils.ErrMissingKeyID):
peerID = uuid.New()
err = nil
} else if err != nil {
case err != nil:
httpapi.Write(ctx, rw, http.StatusUnauthorized, codersdk.Response{
Message: workspacesdk.CoordinateAPIInvalidResumeToken,
Detail: err.Error(),
Expand All @@ -992,7 +993,7 @@ func (api *API) handleResumeToken(ctx context.Context, rw http.ResponseWriter, r
},
})
return peerID, err
} else {
default:
api.Logger.Debug(ctx, "accepted coordinate resume token for peer",
slog.F("peer_id", peerID.String()))
}
Expand Down
7 changes: 4 additions & 3 deletions coderd/workspacestats/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,17 @@ func (r *Reporter) ReportAgentStats(ctx context.Context, now time.Time, workspac
templateSchedule, err := (*(r.opts.TemplateScheduleStore.Load())).Get(ctx, r.opts.Database, workspace.TemplateID)
// If the template schedule fails to load, just default to bumping
// without the next transition and log it.
if err == nil {
switch {
case err == nil:
next, allowed := schedule.NextAutostart(now, workspace.AutostartSchedule.String, templateSchedule)
if allowed {
nextAutostart = next
}
} else if database.IsQueryCanceledError(err) {
case database.IsQueryCanceledError(err):
r.opts.Logger.Debug(ctx, "query canceled while loading template schedule",
slog.F("workspace_id", workspace.ID),
slog.F("template_id", workspace.TemplateID))
} else {
default:
r.opts.Logger.Error(ctx, "failed to load template schedule bumping activity, defaulting to bumping by 60min",
slog.F("workspace_id", workspace.ID),
slog.F("template_id", workspace.TemplateID),
Expand Down
Loading
Loading