Skip to content

Commit e44fd9b

Browse files
authored
Merge pull request #2205 from bigmoonbit/master
refactor: replace interface{} with any for clarity and modernization
2 parents 275e592 + ef2ef76 commit e44fd9b

File tree

11 files changed

+57
-57
lines changed

11 files changed

+57
-57
lines changed

internal/cadence/lint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (r *lintResult) String() string {
238238
return sb.String()
239239
}
240240

241-
func (r *lintResult) JSON() interface{} {
241+
func (r *lintResult) JSON() any {
242242
return r
243243
}
244244

internal/command/command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ func checkVersion(logger output.Logger) {
285285
}(resp.Body)
286286

287287
body, _ := io.ReadAll(resp.Body)
288-
var data map[string]interface{}
288+
var data map[string]any
289289
err = json.Unmarshal(body, &data)
290290
if err != nil {
291291
return
292292
}
293293

294-
versions, ok := data["versions"].(map[string]interface{})
294+
versions, ok := data["versions"].(map[string]any)
295295
if !ok {
296296
return
297297
}

internal/emulator/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func trackRequestMiddleware(next http.Handler) http.Handler {
137137
func init() {
138138
// Configure zerolog to use console format matching the emulator's output
139139
consoleWriter := zerolog.ConsoleWriter{Out: os.Stderr}
140-
consoleWriter.FormatMessage = func(i interface{}) string {
140+
consoleWriter.FormatMessage = func(i any) string {
141141
if i == nil {
142142
return ""
143143
}

internal/super/generator/contract_template.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type ContractTemplate struct {
4141
FileName string // Optional: If set, use this for the file name instead of Name
4242
Account string
4343
TemplatePath string
44-
Data map[string]interface{}
44+
Data map[string]any
4545
SkipTests bool
4646
AddTestAlias bool
4747
Aliases config.Aliases // Optional: Custom aliases for the contract
@@ -64,8 +64,8 @@ func (c ContractTemplate) GetTemplatePath() string {
6464
return c.TemplatePath
6565
}
6666

67-
func (c ContractTemplate) GetData() map[string]interface{} {
68-
data := map[string]interface{}{
67+
func (c ContractTemplate) GetData() map[string]any {
68+
data := map[string]any{
6969
"Name": c.Name,
7070
}
7171
maps.Copy(data, c.Data)
@@ -120,7 +120,7 @@ func (c ContractTemplate) GetChildren() []TemplateItem {
120120
TestTemplate{
121121
Name: c.Name,
122122
TemplatePath: "contract_init_test.cdc.tmpl",
123-
Data: map[string]interface{}{
123+
Data: map[string]any{
124124
"ContractName": c.Name,
125125
},
126126
},

internal/super/generator/file_template.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ import (
2626
type FileTemplate struct {
2727
TemplatePath string
2828
TargetPath string
29-
Data map[string]interface{}
29+
Data map[string]any
3030
}
3131

3232
func NewFileTemplate(
3333
templatePath string,
3434
targetPath string,
35-
data map[string]interface{},
35+
data map[string]any,
3636
) FileTemplate {
3737
return FileTemplate{
3838
TemplatePath: templatePath,
@@ -53,7 +53,7 @@ func (c FileTemplate) GetTemplatePath() string {
5353
}
5454

5555
// GetData returns the data of the contract
56-
func (c FileTemplate) GetData() map[string]interface{} {
56+
func (c FileTemplate) GetData() map[string]any {
5757
return c.Data
5858
}
5959

internal/super/generator/generator.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var templatesFS embed.FS
4242
type TemplateItem interface {
4343
GetType() string
4444
GetTemplatePath() string
45-
GetData() map[string]interface{}
45+
GetData() map[string]any
4646
GetTargetPath() string
4747
}
4848

@@ -107,7 +107,7 @@ func (g *Generator) generate(item TemplateItem) error {
107107
templatePath := item.GetTemplatePath()
108108
data := item.GetData()
109109

110-
fileData := make(map[string]interface{})
110+
fileData := make(map[string]any)
111111
maps.Copy(fileData, data)
112112

113113
outputContent, err := g.processTemplate(templatePath, fileData)
@@ -150,7 +150,7 @@ func (g *Generator) generate(item TemplateItem) error {
150150

151151
// processTemplate reads a template file from the embedded filesystem and processes it with the provided data
152152
// If you don't need to provide data, pass nil
153-
func (g *Generator) processTemplate(templatePath string, data map[string]interface{}) (string, error) {
153+
func (g *Generator) processTemplate(templatePath string, data map[string]any) (string, error) {
154154
resolvedPath := filepath.Join("templates", templatePath)
155155
templateData, err := templatesFS.ReadFile(filepath.ToSlash(resolvedPath))
156156
if err != nil {

internal/super/generator/generator_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func TestGenerateTestTemplate(t *testing.T) {
200200
err := g.Create(TestTemplate{
201201
Name: "Foobar",
202202
TemplatePath: "contract_init_test.cdc.tmpl",
203-
Data: map[string]interface{}{
203+
Data: map[string]any{
204204
"ContractName": "Foobar",
205205
}},
206206
)
@@ -234,18 +234,18 @@ func TestGenerateReadmeNoDeps(t *testing.T) {
234234
err := g.Create(FileTemplate{
235235
TemplatePath: "README.md.tmpl",
236236
TargetPath: "README.md",
237-
Data: map[string]interface{}{
238-
"Dependencies": []map[string]interface{}{},
239-
"Contracts": []map[string]interface{}{
237+
Data: map[string]any{
238+
"Dependencies": []map[string]any{},
239+
"Contracts": []map[string]any{
240240
{"Name": "ExampleContract"},
241241
},
242-
"Transactions": []map[string]interface{}{
242+
"Transactions": []map[string]any{
243243
{"Name": "ExampleTransaction"},
244244
},
245-
"Scripts": []map[string]interface{}{
245+
"Scripts": []map[string]any{
246246
{"Name": "ExampleScript"},
247247
},
248-
"Tests": []map[string]interface{}{
248+
"Tests": []map[string]any{
249249
{"Name": "ExampleTest"},
250250
},
251251
},
@@ -268,21 +268,21 @@ func TestGenerateReadmeWithDeps(t *testing.T) {
268268
err := g.Create(FileTemplate{
269269
TemplatePath: "README.md.tmpl",
270270
TargetPath: "README.md",
271-
Data: map[string]interface{}{
272-
"Dependencies": []map[string]interface{}{
271+
Data: map[string]any{
272+
"Dependencies": []map[string]any{
273273
{"Name": "FlowToken"},
274274
{"Name": "FungibleToken"},
275275
},
276-
"Contracts": []map[string]interface{}{
276+
"Contracts": []map[string]any{
277277
{"Name": "ExampleContract"},
278278
},
279-
"Transactions": []map[string]interface{}{
279+
"Transactions": []map[string]any{
280280
{"Name": "ExampleTransaction"},
281281
},
282-
"Scripts": []map[string]interface{}{
282+
"Scripts": []map[string]any{
283283
{"Name": "ExampleScript"},
284284
},
285-
"Tests": []map[string]interface{}{
285+
"Tests": []map[string]any{
286286
{"Name": "ExampleTest"},
287287
},
288288
},

internal/super/generator/script_template.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131
type ScriptTemplate struct {
3232
Name string
3333
TemplatePath string
34-
Data map[string]interface{}
34+
Data map[string]any
3535
}
3636

3737
var _ TemplateItem = ScriptTemplate{}
@@ -48,7 +48,7 @@ func (o ScriptTemplate) GetTemplatePath() string {
4848
return o.TemplatePath
4949
}
5050

51-
func (o ScriptTemplate) GetData() map[string]interface{} {
51+
func (o ScriptTemplate) GetData() map[string]any {
5252
return o.Data
5353
}
5454

internal/super/generator/test_template.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131
type TestTemplate struct {
3232
Name string
3333
TemplatePath string
34-
Data map[string]interface{}
34+
Data map[string]any
3535
}
3636

3737
var _ TemplateItem = TestTemplate{}
@@ -50,7 +50,7 @@ func (t TestTemplate) GetTemplatePath() string {
5050
}
5151

5252
// GetData returns the data of the script or transaction
53-
func (t TestTemplate) GetData() map[string]interface{} {
53+
func (t TestTemplate) GetData() map[string]any {
5454
return t.Data
5555
}
5656

internal/super/generator/transaction_template.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
type TransactionTemplate struct {
3333
Name string
3434
TemplatePath string
35-
Data map[string]interface{}
35+
Data map[string]any
3636
}
3737

3838
var _ TemplateItem = TransactionTemplate{}
@@ -51,7 +51,7 @@ func (o TransactionTemplate) GetTemplatePath() string {
5151
}
5252

5353
// GetData returns the data of the script or transaction
54-
func (o TransactionTemplate) GetData() map[string]interface{} {
54+
func (o TransactionTemplate) GetData() map[string]any {
5555
return o.Data
5656
}
5757

0 commit comments

Comments
 (0)