Skip to content

Commit 3c5408e

Browse files
authored
chore: Use any instead of interface{} (#3584)
1 parent b52ed30 commit 3c5408e

Some content is hidden

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

42 files changed

+332
-210
lines changed

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ linters-settings:
106106
- name: unexported-naming
107107
- name: unexported-return
108108
- name: unreachable-code
109+
- name: use-any
109110
- name: var-declaration
110111
- name: var-naming
111112
issues:

github/actions_secrets.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ type PublicKey struct {
2323
// do not error out when unmarshaling.
2424
func (p *PublicKey) UnmarshalJSON(data []byte) error {
2525
var pk struct {
26-
KeyID interface{} `json:"key_id"`
27-
Key *string `json:"key"`
26+
KeyID any `json:"key_id"`
27+
Key *string `json:"key"`
2828
}
2929

3030
if err := json.Unmarshal(data, &pk); err != nil {

github/actions_workflows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type CreateWorkflowDispatchEventRequest struct {
5353
// Inputs represents input keys and values configured in the workflow file.
5454
// The maximum number of properties is 10.
5555
// Default: Any default properties configured in the workflow file will be used when `inputs` are omitted.
56-
Inputs map[string]interface{} `json:"inputs,omitempty"`
56+
Inputs map[string]any `json:"inputs,omitempty"`
5757
}
5858

5959
// ListWorkflows lists all workflows in a repository.

github/actions_workflows_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func TestActionsService_CreateWorkflowDispatchEventByID(t *testing.T) {
237237

238238
event := CreateWorkflowDispatchEventRequest{
239239
Ref: "d4cfb6e7",
240-
Inputs: map[string]interface{}{
240+
Inputs: map[string]any{
241241
"key": "value",
242242
},
243243
}
@@ -281,7 +281,7 @@ func TestActionsService_CreateWorkflowDispatchEventByFileName(t *testing.T) {
281281

282282
event := CreateWorkflowDispatchEventRequest{
283283
Ref: "d4cfb6e7",
284-
Inputs: map[string]interface{}{
284+
Inputs: map[string]any{
285285
"key": "value",
286286
},
287287
}
@@ -618,7 +618,7 @@ func TestCreateWorkflowDispatchEventRequest_Marshal(t *testing.T) {
618618
t.Parallel()
619619
testJSONMarshal(t, &CreateWorkflowDispatchEventRequest{}, "{}")
620620

621-
inputs := make(map[string]interface{}, 0)
621+
inputs := make(map[string]any, 0)
622622
inputs["key"] = "value"
623623

624624
u := &CreateWorkflowDispatchEventRequest{

github/activity_events_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func TestActivityService_EventParsePayload_typed(t *testing.T) {
437437
}
438438

439439
// TestEvent_Payload_untyped checks that unrecognized events are parsed to an
440-
// interface{} value (instead of being discarded or throwing an error), for
440+
// any value (instead of being discarded or throwing an error), for
441441
// forward compatibility with new event types.
442442
func TestActivityService_EventParsePayload_untyped(t *testing.T) {
443443
t.Parallel()
@@ -447,7 +447,7 @@ func TestActivityService_EventParsePayload_untyped(t *testing.T) {
447447
t.Fatalf("Unmarshal Event returned error: %v", err)
448448
}
449449

450-
want := map[string]interface{}{"field": "val"}
450+
want := map[string]any{"field": "val"}
451451
got, err := event.ParsePayload()
452452
if err != nil {
453453
t.Fatalf("ParsePayload returned unexpected error: %v", err)

github/copilot.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ type ListCopilotSeatsResponse struct {
4646
// CopilotSeatDetails represents the details of a Copilot for Business seat.
4747
type CopilotSeatDetails struct {
4848
// Assignee can either be a User, Team, or Organization.
49-
Assignee interface{} `json:"assignee"`
50-
AssigningTeam *Team `json:"assigning_team,omitempty"`
51-
PendingCancellationDate *string `json:"pending_cancellation_date,omitempty"`
52-
LastActivityAt *Timestamp `json:"last_activity_at,omitempty"`
53-
LastActivityEditor *string `json:"last_activity_editor,omitempty"`
54-
CreatedAt *Timestamp `json:"created_at"`
55-
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
56-
PlanType *string `json:"plan_type,omitempty"`
49+
Assignee any `json:"assignee"`
50+
AssigningTeam *Team `json:"assigning_team,omitempty"`
51+
PendingCancellationDate *string `json:"pending_cancellation_date,omitempty"`
52+
LastActivityAt *Timestamp `json:"last_activity_at,omitempty"`
53+
LastActivityEditor *string `json:"last_activity_editor,omitempty"`
54+
CreatedAt *Timestamp `json:"created_at"`
55+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
56+
PlanType *string `json:"plan_type,omitempty"`
5757
}
5858

5959
// SeatAssignments represents the number of seats assigned.
@@ -203,7 +203,7 @@ func (cp *CopilotSeatDetails) UnmarshalJSON(data []byte) error {
203203
cp.PlanType = seatDetail.PlanType
204204

205205
switch v := seatDetail.Assignee.(type) {
206-
case map[string]interface{}:
206+
case map[string]any:
207207
jsonData, err := json.Marshal(seatDetail.Assignee)
208208
if err != nil {
209209
return err

github/enterprise_audit_log_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestEnterpriseService_GetAuditLog(t *testing.T) {
6161
Actor: Ptr("testactor"),
6262
CreatedAt: &Timestamp{timestamp},
6363
Org: Ptr("o"),
64-
AdditionalFields: map[string]interface{}{
64+
AdditionalFields: map[string]any{
6565
"completed_at": "2021-03-07T00:35:08.000Z",
6666
"conclusion": "success",
6767
"event": "schedule",

github/event.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (e Event) String() string {
2727

2828
// ParsePayload parses the event payload. For recognized event types,
2929
// a value of the corresponding struct type will be returned.
30-
func (e *Event) ParsePayload() (interface{}, error) {
30+
func (e *Event) ParsePayload() (any, error) {
3131
// It would be nice if e.Type were the snake_case name of the event,
3232
// but the existing interface uses the struct name instead.
3333
payload := EventForType(typeToMessageMapping[e.GetType()])
@@ -44,7 +44,7 @@ func (e *Event) ParsePayload() (interface{}, error) {
4444
//
4545
// Deprecated: Use ParsePayload instead, which returns an error
4646
// rather than panics if JSON unmarshaling raw payload fails.
47-
func (e *Event) Payload() (payload interface{}) {
47+
func (e *Event) Payload() (payload any) {
4848
var err error
4949
payload, err = e.ParsePayload()
5050
if err != nil {

github/event_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestEvent_Marshal(t *testing.T) {
4949
t.Parallel()
5050
testJSONMarshal(t, &Event{}, "{}")
5151

52-
l := make(map[string]interface{})
52+
l := make(map[string]any)
5353
l["key"] = "value"
5454

5555
jsonMsg, _ := json.Marshal(&l)

github/event_types.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,44 +1400,44 @@ func (h HeadCommit) String() string {
14001400

14011401
// PushEventRepository represents the repo object in a PushEvent payload.
14021402
type PushEventRepository struct {
1403-
ID *int64 `json:"id,omitempty"`
1404-
NodeID *string `json:"node_id,omitempty"`
1405-
Name *string `json:"name,omitempty"`
1406-
FullName *string `json:"full_name,omitempty"`
1407-
Owner *User `json:"owner,omitempty"`
1408-
Private *bool `json:"private,omitempty"`
1409-
Description *string `json:"description,omitempty"`
1410-
Fork *bool `json:"fork,omitempty"`
1411-
CreatedAt *Timestamp `json:"created_at,omitempty"`
1412-
PushedAt *Timestamp `json:"pushed_at,omitempty"`
1413-
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
1414-
Homepage *string `json:"homepage,omitempty"`
1415-
PullsURL *string `json:"pulls_url,omitempty"`
1416-
Size *int `json:"size,omitempty"`
1417-
StargazersCount *int `json:"stargazers_count,omitempty"`
1418-
WatchersCount *int `json:"watchers_count,omitempty"`
1419-
Language *string `json:"language,omitempty"`
1420-
HasIssues *bool `json:"has_issues,omitempty"`
1421-
HasDownloads *bool `json:"has_downloads,omitempty"`
1422-
HasWiki *bool `json:"has_wiki,omitempty"`
1423-
HasPages *bool `json:"has_pages,omitempty"`
1424-
ForksCount *int `json:"forks_count,omitempty"`
1425-
Archived *bool `json:"archived,omitempty"`
1426-
Disabled *bool `json:"disabled,omitempty"`
1427-
OpenIssuesCount *int `json:"open_issues_count,omitempty"`
1428-
DefaultBranch *string `json:"default_branch,omitempty"`
1429-
MasterBranch *string `json:"master_branch,omitempty"`
1430-
Organization *string `json:"organization,omitempty"`
1431-
URL *string `json:"url,omitempty"`
1432-
ArchiveURL *string `json:"archive_url,omitempty"`
1433-
HTMLURL *string `json:"html_url,omitempty"`
1434-
StatusesURL *string `json:"statuses_url,omitempty"`
1435-
GitURL *string `json:"git_url,omitempty"`
1436-
SSHURL *string `json:"ssh_url,omitempty"`
1437-
CloneURL *string `json:"clone_url,omitempty"`
1438-
SVNURL *string `json:"svn_url,omitempty"`
1439-
Topics []string `json:"topics,omitempty"`
1440-
CustomProperties map[string]interface{} `json:"custom_properties,omitempty"`
1403+
ID *int64 `json:"id,omitempty"`
1404+
NodeID *string `json:"node_id,omitempty"`
1405+
Name *string `json:"name,omitempty"`
1406+
FullName *string `json:"full_name,omitempty"`
1407+
Owner *User `json:"owner,omitempty"`
1408+
Private *bool `json:"private,omitempty"`
1409+
Description *string `json:"description,omitempty"`
1410+
Fork *bool `json:"fork,omitempty"`
1411+
CreatedAt *Timestamp `json:"created_at,omitempty"`
1412+
PushedAt *Timestamp `json:"pushed_at,omitempty"`
1413+
UpdatedAt *Timestamp `json:"updated_at,omitempty"`
1414+
Homepage *string `json:"homepage,omitempty"`
1415+
PullsURL *string `json:"pulls_url,omitempty"`
1416+
Size *int `json:"size,omitempty"`
1417+
StargazersCount *int `json:"stargazers_count,omitempty"`
1418+
WatchersCount *int `json:"watchers_count,omitempty"`
1419+
Language *string `json:"language,omitempty"`
1420+
HasIssues *bool `json:"has_issues,omitempty"`
1421+
HasDownloads *bool `json:"has_downloads,omitempty"`
1422+
HasWiki *bool `json:"has_wiki,omitempty"`
1423+
HasPages *bool `json:"has_pages,omitempty"`
1424+
ForksCount *int `json:"forks_count,omitempty"`
1425+
Archived *bool `json:"archived,omitempty"`
1426+
Disabled *bool `json:"disabled,omitempty"`
1427+
OpenIssuesCount *int `json:"open_issues_count,omitempty"`
1428+
DefaultBranch *string `json:"default_branch,omitempty"`
1429+
MasterBranch *string `json:"master_branch,omitempty"`
1430+
Organization *string `json:"organization,omitempty"`
1431+
URL *string `json:"url,omitempty"`
1432+
ArchiveURL *string `json:"archive_url,omitempty"`
1433+
HTMLURL *string `json:"html_url,omitempty"`
1434+
StatusesURL *string `json:"statuses_url,omitempty"`
1435+
GitURL *string `json:"git_url,omitempty"`
1436+
SSHURL *string `json:"ssh_url,omitempty"`
1437+
CloneURL *string `json:"clone_url,omitempty"`
1438+
SVNURL *string `json:"svn_url,omitempty"`
1439+
Topics []string `json:"topics,omitempty"`
1440+
CustomProperties map[string]any `json:"custom_properties,omitempty"`
14411441
}
14421442

14431443
// PushEventRepoOwner is a basic representation of user/org in a PushEvent payload.

0 commit comments

Comments
 (0)