Skip to content

Commit 9d13c60

Browse files
committed
build: move to any from interface{}
1 parent 1cd5fe4 commit 9d13c60

File tree

8 files changed

+33
-33
lines changed

8 files changed

+33
-33
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ if err != nil {
9494
recordsToSend := &airtable.Records{
9595
Records: []*airtable.Record{
9696
{
97-
Fields: map[string]interface{}{
97+
Fields: map[string]any{
9898
"Field1": "value1",
9999
"Field2": true,
100100
},
@@ -121,7 +121,7 @@ if err != nil {
121121
To partial update one record
122122

123123
```Go
124-
res, err := record.UpdateRecordPartial(map[string]interface{}{"Field_2": false})
124+
res, err := record.UpdateRecordPartial(map[string]any{"Field_2": false})
125125
if err != nil {
126126
// Handle error
127127
}
@@ -133,13 +133,13 @@ To full update records
133133
toUpdateRecords := &airtable.Records{
134134
Records: []*airtable.Record{
135135
{
136-
Fields: map[string]interface{}{
136+
Fields: map[string]any{
137137
"Field1": "value1",
138138
"Field2": true,
139139
},
140140
},
141141
{
142-
Fields: map[string]interface{}{
142+
Fields: map[string]any{
143143
"Field1": "value1",
144144
"Field2": true,
145145
},

base.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ type Bases struct {
1919
}
2020

2121
type Field struct {
22-
ID string `json:"id"`
23-
Type string `json:"type"`
24-
Name string `json:"name"`
25-
Description string `json:"description"`
26-
Options map[string]interface{} `json:"options"`
22+
ID string `json:"id"`
23+
Type string `json:"type"`
24+
Name string `json:"name"`
25+
Description string `json:"description"`
26+
Options map[string]any `json:"options"`
2727
}
2828

2929
type View struct {

client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (at *Client) rateLimit() {
7777
<-at.rateLimiter
7878
}
7979

80-
func (at *Client) get(ctx context.Context, db, table, recordID string, params url.Values, target interface{}) error {
80+
func (at *Client) get(ctx context.Context, db, table, recordID string, params url.Values, target any) error {
8181
at.rateLimit()
8282

8383
url := fmt.Sprintf("%s/%s/%s", at.baseURL, db, table)
@@ -103,7 +103,7 @@ func (at *Client) get(ctx context.Context, db, table, recordID string, params ur
103103
return nil
104104
}
105105

106-
func (at *Client) post(ctx context.Context, db, table string, data, response interface{}) error {
106+
func (at *Client) post(ctx context.Context, db, table string, data, response any) error {
107107
at.rateLimit()
108108

109109
url := fmt.Sprintf("%s/%s/%s", at.baseURL, db, table)
@@ -124,7 +124,7 @@ func (at *Client) post(ctx context.Context, db, table string, data, response int
124124
return at.do(req, response)
125125
}
126126

127-
func (at *Client) delete(ctx context.Context, db, table string, recordIDs []string, target interface{}) error {
127+
func (at *Client) delete(ctx context.Context, db, table string, recordIDs []string, target any) error {
128128
at.rateLimit()
129129

130130
rawURL := fmt.Sprintf("%s/%s/%s", at.baseURL, db, table)
@@ -152,7 +152,7 @@ func (at *Client) delete(ctx context.Context, db, table string, recordIDs []stri
152152
return nil
153153
}
154154

155-
func (at *Client) patch(ctx context.Context, db, table, data, response interface{}) error {
155+
func (at *Client) patch(ctx context.Context, db, table, data, response any) error {
156156
at.rateLimit()
157157

158158
url := fmt.Sprintf("%s/%s/%s", at.baseURL, db, table)
@@ -173,7 +173,7 @@ func (at *Client) patch(ctx context.Context, db, table, data, response interface
173173
return at.do(req, response)
174174
}
175175

176-
func (at *Client) put(ctx context.Context, db, table, data, response interface{}) error {
176+
func (at *Client) put(ctx context.Context, db, table, data, response any) error {
177177
at.rateLimit()
178178

179179
url := fmt.Sprintf("%s/%s/%s", at.baseURL, db, table)
@@ -194,7 +194,7 @@ func (at *Client) put(ctx context.Context, db, table, data, response interface{}
194194
return at.do(req, response)
195195
}
196196

197-
func (at *Client) do(req *http.Request, response interface{}) error {
197+
func (at *Client) do(req *http.Request, response any) error {
198198
if req == nil {
199199
return errors.New("nil request")
200200
}

field-converter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ const (
1616

1717
var ErrNotDateTime = errors.New("field is not date time")
1818

19-
func ToDateTime(field interface{}) (time.Time, error) {
19+
func ToDateTime(field any) (time.Time, error) {
2020
fS, err := field.(string)
2121
if !err {
2222
return time.Time{}, ErrNotDateTime
2323
}
2424
return time.Parse(dateTimeFormat, fS)
2525
}
2626

27-
func FromDateTime(t time.Time) interface{} {
27+
func FromDateTime(t time.Time) any {
2828
return t.Format(dateTimeFormat)
2929
}

field-converter_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import (
1414
func TestToDateTime(t *testing.T) {
1515
tests := []struct {
1616
name string
17-
field interface{}
17+
field any
1818
want time.Time
1919
wantErr bool
2020
}{
21-
{"not string", interface{}(1), time.Time{}, true},
22-
{"string not time", interface{}("hello"), time.Time{}, true},
23-
{"string time", interface{}("2022-03-24T11:12:13.000Z"), time.Date(2022, 0o3, 24, 11, 12, 13, 0, time.UTC), false},
21+
{"not string", any(1), time.Time{}, true},
22+
{"string not time", any("hello"), time.Time{}, true},
23+
{"string time", any("2022-03-24T11:12:13.000Z"), time.Date(2022, 0o3, 24, 11, 12, 13, 0, time.UTC), false},
2424
}
2525
for _, tt := range tests {
2626
t.Run(tt.name, func(t *testing.T) {
@@ -40,9 +40,9 @@ func TestFromDateTime(t *testing.T) {
4040
tests := []struct {
4141
name string
4242
t time.Time
43-
want interface{}
43+
want any
4444
}{
45-
{"positive", time.Date(2022, 0o3, 24, 11, 12, 13, 1, time.UTC), interface{}("2022-03-24T11:12:13.000Z")},
45+
{"positive", time.Date(2022, 0o3, 24, 11, 12, 13, 1, time.UTC), any("2022-03-24T11:12:13.000Z")},
4646
}
4747
for _, tt := range tests {
4848
t.Run(tt.name, func(t *testing.T) {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module github.com/mehanizm/airtable
22

3-
go 1.19
3+
go 1.20

record.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ import (
1414
type Record struct {
1515
client *Client
1616
table *Table
17-
ID string `json:"id,omitempty"`
18-
Fields map[string]interface{} `json:"fields"`
19-
CreatedTime string `json:"createdTime,omitempty"`
20-
Deleted bool `json:"deleted,omitempty"`
17+
ID string `json:"id,omitempty"`
18+
Fields map[string]any `json:"fields"`
19+
CreatedTime string `json:"createdTime,omitempty"`
20+
Deleted bool `json:"deleted,omitempty"`
2121

2222
// The Airtable API will perform best-effort automatic data conversion
2323
// from string values if the typecast parameter is passed in.
@@ -49,13 +49,13 @@ func (t *Table) GetRecordContext(ctx context.Context, recordID string) (*Record,
4949
}
5050

5151
// UpdateRecordPartial updates partial info on record.
52-
func (r *Record) UpdateRecordPartial(changedFields map[string]interface{}) (*Record, error) {
52+
func (r *Record) UpdateRecordPartial(changedFields map[string]any) (*Record, error) {
5353
return r.UpdateRecordPartialContext(context.Background(), changedFields)
5454
}
5555

5656
// UpdateRecordPartialContext updates partial info on record
5757
// with custom context
58-
func (r *Record) UpdateRecordPartialContext(ctx context.Context, changedFields map[string]interface{}) (*Record, error) {
58+
func (r *Record) UpdateRecordPartialContext(ctx context.Context, changedFields map[string]any) (*Record, error) {
5959
data := &Records{
6060
Records: []*Record{
6161
{

record_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestRecord_GetRecord(t *testing.T) {
2323
table: table,
2424
ID: "recnTq6CsvFM6vX2m",
2525
CreatedTime: "2020-04-10T11:30:57.000Z",
26-
Fields: map[string]interface{}{
26+
Fields: map[string]any{
2727
"Field1": "Field1",
2828
"Field2": true,
2929
"Field3": "2020-04-06T06:00:00.000Z",
@@ -61,7 +61,7 @@ func TestRecord_DeleteRecord(t *testing.T) {
6161
func TestRecord_UpdateRecordPartial(t *testing.T) {
6262
record := testRecord(t)
6363
record.client.baseURL = mockResponse("get_records_with_filter.json").URL
64-
res, err := record.UpdateRecordPartial(map[string]interface{}{"Field_2": true})
64+
res, err := record.UpdateRecordPartial(map[string]any{"Field_2": true})
6565
if err != nil {
6666
t.Error("must be no error")
6767
}
@@ -73,7 +73,7 @@ func TestRecord_UpdateRecordPartial(t *testing.T) {
7373
t.Errorf("expected that Field_2 will be true, but was: %#v", res.Fields["Field2"].(bool))
7474
}
7575
record.client.baseURL = mockErrorResponse(404).URL
76-
_, err = record.UpdateRecordPartial(map[string]interface{}{})
76+
_, err = record.UpdateRecordPartial(map[string]any{})
7777
var e *HTTPClientError
7878
if errors.Is(err, e) {
7979
t.Errorf("should be an http error, but was not: %v", err)

0 commit comments

Comments
 (0)