Skip to content

Commit a83befa

Browse files
dvyukova-nogikh
authored andcommitted
all: use any instead of interface{}
Any is the preferred over interface{} now in Go.
1 parent 8fb7048 commit a83befa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+214
-214
lines changed

dashboard/app/api.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ var apiHandlers = map[string]APIHandler{
7777
"log_to_repro": nsHandler(apiLogToReproduce),
7878
}
7979

80-
type JSONHandler func(c context.Context, r *http.Request) (interface{}, error)
81-
type APIHandler func(c context.Context, payload io.Reader) (interface{}, error)
80+
type JSONHandler func(c context.Context, r *http.Request) (any, error)
81+
type APIHandler func(c context.Context, payload io.Reader) (any, error)
8282

8383
const (
8484
maxReproPerBug = 10
@@ -126,7 +126,7 @@ func handleJSON(fn JSONHandler) http.Handler {
126126
})
127127
}
128128

129-
func handleAPI(c context.Context, r *http.Request) (interface{}, error) {
129+
func handleAPI(c context.Context, r *http.Request) (any, error) {
130130
client := r.PostFormValue("client")
131131
method := r.PostFormValue("method")
132132
log.Infof(c, "api %q from %q", method, client)
@@ -178,7 +178,7 @@ func contextNamespace(c context.Context) string {
178178
// gcsPayloadHandler json.Decode the gcsURL from payload and stream pointed content.
179179
// This function streams ungzipped content in order to be aligned with other wrappers/handlers.
180180
func gcsPayloadHandler(handler APIHandler) APIHandler {
181-
return func(c context.Context, payload io.Reader) (interface{}, error) {
181+
return func(c context.Context, payload io.Reader) (any, error) {
182182
var gcsURL string
183183
if err := json.NewDecoder(payload).Decode(&gcsURL); err != nil {
184184
return nil, fmt.Errorf("json.NewDecoder(payload).Decode(&gcsURL): %w", err)
@@ -216,7 +216,7 @@ func nsHandler[Req any](handler func(context.Context, string, *Req) (any, error)
216216
}
217217

218218
func typedHandler[Req any](handler func(context.Context, *Req) (any, error)) APIHandler {
219-
return func(ctx context.Context, payload io.Reader) (interface{}, error) {
219+
return func(ctx context.Context, payload io.Reader) (any, error) {
220220
req := new(Req)
221221
if payload != nil {
222222
if err := json.NewDecoder(payload).Decode(req); err != nil {
@@ -227,12 +227,12 @@ func typedHandler[Req any](handler func(context.Context, *Req) (any, error)) API
227227
}
228228
}
229229

230-
func apiLogError(c context.Context, req *dashapi.LogEntry) (interface{}, error) {
230+
func apiLogError(c context.Context, req *dashapi.LogEntry) (any, error) {
231231
log.Errorf(c, "%v: %v", req.Name, req.Text)
232232
return nil, nil
233233
}
234234

235-
func apiBuilderPoll(c context.Context, ns string, req *dashapi.BuilderPollReq) (interface{}, error) {
235+
func apiBuilderPoll(c context.Context, ns string, req *dashapi.BuilderPollReq) (any, error) {
236236
bugs, _, err := loadAllBugs(c, func(query *db.Query) *db.Query {
237237
return query.Filter("Namespace=", ns).
238238
Filter("Status<", BugStatusFixed)
@@ -277,7 +277,7 @@ func reportEmail(c context.Context, ns string) string {
277277
return ""
278278
}
279279

280-
func apiCommitPoll(c context.Context, ns string, req *any) (interface{}, error) {
280+
func apiCommitPoll(c context.Context, ns string, req *any) (any, error) {
281281
resp := &dashapi.CommitPollResp{
282282
ReportEmail: reportEmail(c, ns),
283283
}
@@ -343,7 +343,7 @@ func pollBackportCommits(c context.Context, ns string, count int) ([]string, err
343343
return backportTitles, nil
344344
}
345345

346-
func apiUploadCommits(c context.Context, ns string, req *dashapi.CommitPollResultReq) (interface{}, error) {
346+
func apiUploadCommits(c context.Context, ns string, req *dashapi.CommitPollResultReq) (any, error) {
347347
// This adds fixing commits to bugs.
348348
err := addCommitsToBugs(c, ns, "", nil, req.Commits)
349349
if err != nil {
@@ -444,7 +444,7 @@ func addCommitInfoToBugImpl(c context.Context, bug *Bug, com dashapi.Commit) (bo
444444
return changed, nil
445445
}
446446

447-
func apiJobPoll(c context.Context, req *dashapi.JobPollReq) (interface{}, error) {
447+
func apiJobPoll(c context.Context, req *dashapi.JobPollReq) (any, error) {
448448
if stop, err := emergentlyStopped(c); err != nil || stop {
449449
// The bot's operation was aborted. Don't accept new crash reports.
450450
return &dashapi.JobPollResp{}, err
@@ -455,17 +455,17 @@ func apiJobPoll(c context.Context, req *dashapi.JobPollReq) (interface{}, error)
455455
return pollPendingJobs(c, req.Managers)
456456
}
457457

458-
func apiJobDone(c context.Context, req *dashapi.JobDoneReq) (interface{}, error) {
458+
func apiJobDone(c context.Context, req *dashapi.JobDoneReq) (any, error) {
459459
err := doneJob(c, req)
460460
return nil, err
461461
}
462462

463-
func apiJobReset(c context.Context, req *dashapi.JobResetReq) (interface{}, error) {
463+
func apiJobReset(c context.Context, req *dashapi.JobResetReq) (any, error) {
464464
err := resetJobs(c, req)
465465
return nil, err
466466
}
467467

468-
func apiUploadBuild(c context.Context, ns string, req *dashapi.Build) (interface{}, error) {
468+
func apiUploadBuild(c context.Context, ns string, req *dashapi.Build) (any, error) {
469469
now := timeNow(c)
470470
_, isNewBuild, err := uploadBuild(c, now, ns, req, BuildNormal)
471471
if err != nil {
@@ -732,7 +732,7 @@ func managerList(c context.Context, ns string) ([]string, error) {
732732
return managers, nil
733733
}
734734

735-
func apiReportBuildError(c context.Context, ns string, req *dashapi.BuildErrorReq) (interface{}, error) {
735+
func apiReportBuildError(c context.Context, ns string, req *dashapi.BuildErrorReq) (any, error) {
736736
now := timeNow(c)
737737
build, _, err := uploadBuild(c, now, ns, &req.Build, BuildFailed)
738738
if err != nil {
@@ -762,7 +762,7 @@ const (
762762
suppressedReportTitle = "suppressed report"
763763
)
764764

765-
func apiReportCrash(c context.Context, ns string, req *dashapi.Crash) (interface{}, error) {
765+
func apiReportCrash(c context.Context, ns string, req *dashapi.Crash) (any, error) {
766766
if stop, err := emergentlyStopped(c); err != nil || stop {
767767
// The bot's operation was aborted. Don't accept new crash reports.
768768
return &dashapi.ReportCrashResp{}, err
@@ -1067,7 +1067,7 @@ func purgeOldCrashes(c context.Context, bug *Bug, bugKey *db.Key) {
10671067
log.Infof(c, "deleted %v crashes for bug %q", deleted, bug.Title)
10681068
}
10691069

1070-
func apiReportFailedRepro(c context.Context, ns string, req *dashapi.CrashID) (interface{}, error) {
1070+
func apiReportFailedRepro(c context.Context, ns string, req *dashapi.CrashID) (any, error) {
10711071
req.Title = canonicalizeCrashTitle(req.Title, req.Corrupted, req.Suppressed)
10721072
bug, err := findExistingBugForCrash(c, ns, []string{req.Title})
10731073
if err != nil {
@@ -1134,7 +1134,7 @@ func saveReproAttempt(c context.Context, bug *Bug, build *Build, log []byte) err
11341134
return nil
11351135
}
11361136

1137-
func apiNeedRepro(c context.Context, ns string, req *dashapi.CrashID) (interface{}, error) {
1137+
func apiNeedRepro(c context.Context, ns string, req *dashapi.CrashID) (any, error) {
11381138
if req.Corrupted {
11391139
resp := &dashapi.NeedReproResp{
11401140
NeedRepro: false,
@@ -1182,7 +1182,7 @@ func normalizeCrashTitle(title string) string {
11821182
return strings.TrimSpace(limitLength(title, maxTextLen))
11831183
}
11841184

1185-
func apiManagerStats(c context.Context, ns string, req *dashapi.ManagerStatsReq) (interface{}, error) {
1185+
func apiManagerStats(c context.Context, ns string, req *dashapi.ManagerStatsReq) (any, error) {
11861186
now := timeNow(c)
11871187
err := updateManager(c, ns, req.Name, func(mgr *Manager, stats *ManagerStats) error {
11881188
mgr.Link = req.Addr
@@ -1203,7 +1203,7 @@ func apiManagerStats(c context.Context, ns string, req *dashapi.ManagerStatsReq)
12031203
return nil, err
12041204
}
12051205

1206-
func apiUpdateReport(c context.Context, ns string, req *dashapi.UpdateReportReq) (interface{}, error) {
1206+
func apiUpdateReport(c context.Context, ns string, req *dashapi.UpdateReportReq) (any, error) {
12071207
bug := new(Bug)
12081208
bugKey := db.NewKey(c, "Bug", req.BugID, 0, nil)
12091209
if err := db.Get(c, bugKey, bug); err != nil {
@@ -1229,7 +1229,7 @@ func apiUpdateReport(c context.Context, ns string, req *dashapi.UpdateReportReq)
12291229
return nil, runInTransaction(c, tx, nil)
12301230
}
12311231

1232-
func apiBugList(c context.Context, ns string, req *any) (interface{}, error) {
1232+
func apiBugList(c context.Context, ns string, req *any) (any, error) {
12331233
keys, err := db.NewQuery("Bug").
12341234
Filter("Namespace=", ns).
12351235
KeysOnly().
@@ -1244,7 +1244,7 @@ func apiBugList(c context.Context, ns string, req *any) (interface{}, error) {
12441244
return resp, nil
12451245
}
12461246

1247-
func apiLoadBug(c context.Context, ns string, req *dashapi.LoadBugReq) (interface{}, error) {
1247+
func apiLoadBug(c context.Context, ns string, req *dashapi.LoadBugReq) (any, error) {
12481248
bug := new(Bug)
12491249
bugKey := db.NewKey(c, "Bug", req.ID, 0, nil)
12501250
if err := db.Get(c, bugKey, bug); err != nil {
@@ -1256,7 +1256,7 @@ func apiLoadBug(c context.Context, ns string, req *dashapi.LoadBugReq) (interfac
12561256
return loadBugReport(c, bug)
12571257
}
12581258

1259-
func apiLoadFullBug(c context.Context, req *dashapi.LoadFullBugReq) (interface{}, error) {
1259+
func apiLoadFullBug(c context.Context, req *dashapi.LoadFullBugReq) (any, error) {
12601260
bug, bugKey, err := findBugByReportingID(c, req.BugID)
12611261
if err != nil {
12621262
return nil, fmt.Errorf("failed to find the bug: %w", err)
@@ -1282,7 +1282,7 @@ func loadBugReport(c context.Context, bug *Bug) (*dashapi.BugReport, error) {
12821282
return createBugReport(c, bug, crash, crashKey, bugReporting, reporting)
12831283
}
12841284

1285-
func apiAddBuildAssets(c context.Context, ns string, req *dashapi.AddBuildAssetsReq) (interface{}, error) {
1285+
func apiAddBuildAssets(c context.Context, ns string, req *dashapi.AddBuildAssetsReq) (any, error) {
12861286
assets := []Asset{}
12871287
for i, toAdd := range req.Assets {
12881288
asset, err := parseIncomingAsset(c, toAdd, ns)
@@ -1323,7 +1323,7 @@ func parseIncomingAsset(c context.Context, newAsset dashapi.NewAsset, ns string)
13231323
}, nil
13241324
}
13251325

1326-
func apiNeededAssetsList(c context.Context, req *any) (interface{}, error) {
1326+
func apiNeededAssetsList(c context.Context, req *any) (any, error) {
13271327
return queryNeededAssets(c)
13281328
}
13291329

@@ -1704,7 +1704,7 @@ func handleRefreshSubsystems(w http.ResponseWriter, r *http.Request) {
17041704
}
17051705
}
17061706

1707-
func apiSaveDiscussion(c context.Context, req *dashapi.SaveDiscussionReq) (interface{}, error) {
1707+
func apiSaveDiscussion(c context.Context, req *dashapi.SaveDiscussionReq) (any, error) {
17081708
d := req.Discussion
17091709
newBugIDs := []string{}
17101710
for _, id := range d.BugIDs {
@@ -1743,7 +1743,7 @@ func recordEmergencyStop(c context.Context) error {
17431743
// Share crash logs for non-reproduced bugs with syz-managers.
17441744
// In future, this can also take care of repro exchange between instances
17451745
// in the place of syz-hub.
1746-
func apiLogToReproduce(c context.Context, ns string, req *dashapi.LogToReproReq) (interface{}, error) {
1746+
func apiLogToReproduce(c context.Context, ns string, req *dashapi.LogToReproReq) (any, error) {
17471747
build, err := loadBuild(c, ns, req.BuildID)
17481748
if err != nil {
17491749
return nil, err
@@ -1863,15 +1863,15 @@ func takeReproTask(c context.Context, ns, manager string) ([]byte, error) {
18631863
return log, err
18641864
}
18651865

1866-
func apiCreateUploadURL(c context.Context, req *any) (interface{}, error) {
1866+
func apiCreateUploadURL(c context.Context, req *any) (any, error) {
18671867
bucket := getConfig(c).UploadBucket
18681868
if bucket == "" {
18691869
return nil, errors.New("not configured")
18701870
}
18711871
return fmt.Sprintf("%s/%s.upload", bucket, uuid.New().String()), nil
18721872
}
18731873

1874-
func apiSendEmail(c context.Context, req *dashapi.SendEmailReq) (interface{}, error) {
1874+
func apiSendEmail(c context.Context, req *dashapi.SendEmailReq) (any, error) {
18751875
var headers mail.Header
18761876
if req.InReplyTo != "" {
18771877
headers = mail.Header{"In-Reply-To": []string{req.InReplyTo}}
@@ -1889,7 +1889,7 @@ func apiSendEmail(c context.Context, req *dashapi.SendEmailReq) (interface{}, er
18891889
// apiSaveCoverage reads jsonl data from payload and stores it to coveragedb.
18901890
// First payload jsonl line is a coveragedb.HistoryRecord (w/o session and time).
18911891
// Second+ records are coveragedb.JSONLWrapper.
1892-
func apiSaveCoverage(c context.Context, payload io.Reader) (interface{}, error) {
1892+
func apiSaveCoverage(c context.Context, payload io.Reader) (any, error) {
18931893
descr := new(coveragedb.HistoryRecord)
18941894
jsonDec := json.NewDecoder(payload)
18951895
if err := jsonDec.Decode(descr); err != nil {

dashboard/app/coverage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func getParam[T int | string | bool | civil.Date](r *http.Request, name string,
111111
return extractVal(t, r.FormValue(name)).(T)
112112
}
113113

114-
func extractVal(t interface{}, val string) interface{} {
114+
func extractVal(t any, val string) any {
115115
switch t.(type) {
116116
case int:
117117
res, _ := strconv.Atoi(val)

dashboard/app/entities_spanner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ from merge_history join files
4444
on merge_history.session = files.session
4545
where namespace=$1 and duration>=$2 and duration<=$3 and manager='*'
4646
group by dateto, duration`,
47-
Params: map[string]interface{}{
47+
Params: map[string]any{
4848
"p1": ns,
4949
"p2": minDays,
5050
"p3": maxDays,

dashboard/app/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func handleAuth(fn contextHandler) contextHandler {
203203
}
204204
}
205205

206-
func serveTemplate(w http.ResponseWriter, name string, data interface{}) error {
206+
func serveTemplate(w http.ResponseWriter, name string, data any) error {
207207
buf := new(bytes.Buffer)
208208
if err := templates.ExecuteTemplate(buf, name, data); err != nil {
209209
return err

dashboard/app/jobs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ func pollCompletedJobs(c context.Context, typ string) ([]*dashapi.BugReport, err
12581258
return reports, nil
12591259
}
12601260

1261-
func createBugReportForJob(c context.Context, job *Job, jobKey *db.Key, config interface{}) (
1261+
func createBugReportForJob(c context.Context, job *Job, jobKey *db.Key, config any) (
12621262
*dashapi.BugReport, error) {
12631263
reportingConfig, err := json.Marshal(config)
12641264
if err != nil {

dashboard/app/label.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type subsetOf []string
3232
type trueFalse struct{}
3333

3434
func makeLabelSet(c context.Context, ns string) *labelSet {
35-
ret := map[BugLabelType]interface{}{
35+
ret := map[BugLabelType]any{
3636
PriorityLabel: oneOf([]string{
3737
string(LowPrioBug),
3838
string(NormalPrioBug),
@@ -74,7 +74,7 @@ func makeLabelSet(c context.Context, ns string) *labelSet {
7474
type labelSet struct {
7575
c context.Context
7676
ns string
77-
labels map[BugLabelType]interface{}
77+
labels map[BugLabelType]any
7878
}
7979

8080
func (s *labelSet) FindLabel(label BugLabelType) bool {

dashboard/app/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ type uiCollapsible struct {
318318
Title string
319319
Show bool // By default it's collapsed.
320320
Type string // Template system understands it.
321-
Value interface{}
321+
Value any
322322
}
323323

324324
func makeCollapsibleBugJobs(title string, jobs []*uiJob) *uiCollapsible {
@@ -1411,7 +1411,7 @@ func handleBugSummaries(c context.Context, w http.ResponseWriter, r *http.Reques
14111411
return json.NewEncoder(w).Encode(list)
14121412
}
14131413

1414-
func writeJSONVersionOf(writer http.ResponseWriter, page interface{}) error {
1414+
func writeJSONVersionOf(writer http.ResponseWriter, page any) error {
14151415
data, err := GetJSONDescrFor(page)
14161416
if err != nil {
14171417
return err

dashboard/app/public_json_api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ func getExtAPIDescrForBackports(groups []*uiBackportGroup) *publicAPIBackports {
161161
}
162162
}
163163

164-
func GetJSONDescrFor(page interface{}) ([]byte, error) {
165-
var res interface{}
164+
func GetJSONDescrFor(page any) ([]byte, error) {
165+
var res any
166166
switch i := page.(type) {
167167
case *uiBugPage:
168168
res = getExtAPIDescrForBugPage(i)

dashboard/app/reporting_external.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// The external system is meant to poll for new bugs with apiReportingPoll,
1616
// and report back bug status updates with apiReportingUpdate.
1717

18-
func apiReportingPollBugs(c context.Context, req *dashapi.PollBugsRequest) (interface{}, error) {
18+
func apiReportingPollBugs(c context.Context, req *dashapi.PollBugsRequest) (any, error) {
1919
if stop, err := emergentlyStopped(c); err != nil || stop {
2020
return &dashapi.PollBugsResponse{}, err
2121
}
@@ -32,7 +32,7 @@ func apiReportingPollBugs(c context.Context, req *dashapi.PollBugsRequest) (inte
3232
}
3333

3434
func apiReportingPollNotifications(c context.Context, req *dashapi.PollNotificationsRequest) (
35-
interface{}, error) {
35+
any, error) {
3636
if stop, err := emergentlyStopped(c); err != nil || stop {
3737
return &dashapi.PollNotificationsResponse{}, err
3838
}
@@ -43,7 +43,7 @@ func apiReportingPollNotifications(c context.Context, req *dashapi.PollNotificat
4343
return resp, nil
4444
}
4545

46-
func apiReportingPollClosed(c context.Context, req *dashapi.PollClosedRequest) (interface{}, error) {
46+
func apiReportingPollClosed(c context.Context, req *dashapi.PollClosedRequest) (any, error) {
4747
if stop, err := emergentlyStopped(c); err != nil || stop {
4848
return &dashapi.PollClosedResponse{}, err
4949
}
@@ -57,7 +57,7 @@ func apiReportingPollClosed(c context.Context, req *dashapi.PollClosedRequest) (
5757
return resp, nil
5858
}
5959

60-
func apiReportingUpdate(c context.Context, req *dashapi.BugUpdate) (interface{}, error) {
60+
func apiReportingUpdate(c context.Context, req *dashapi.BugUpdate) (any, error) {
6161
if req.JobID != "" {
6262
resp := &dashapi.BugUpdateReply{
6363
OK: true,
@@ -78,7 +78,7 @@ func apiReportingUpdate(c context.Context, req *dashapi.BugUpdate) (interface{},
7878
}, nil
7979
}
8080

81-
func apiNewTestJob(c context.Context, req *dashapi.TestPatchRequest) (interface{}, error) {
81+
func apiNewTestJob(c context.Context, req *dashapi.TestPatchRequest) (any, error) {
8282
resp := &dashapi.TestPatchReply{}
8383
err := handleExternalTestRequest(c, req)
8484
if err != nil {

dashboard/app/subsystem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ type (
108108
)
109109

110110
func updateBugSubsystems(c context.Context, bugKey *db.Key,
111-
list []*subsystem.Subsystem, info interface{}) error {
111+
list []*subsystem.Subsystem, info any) error {
112112
now := timeNow(c)
113113
return updateSingleBug(c, bugKey, func(bug *Bug) error {
114114
switch v := info.(type) {

0 commit comments

Comments
 (0)