@@ -5,13 +5,16 @@ import (
55 "encoding/json"
66 "fmt"
77 "go/format"
8- "io/ioutil "
8+ "io"
99 "net/http"
1010 "net/url"
1111 "os"
1212 "sort"
1313 "strings"
1414 "text/template"
15+
16+ "golang.org/x/text/cases"
17+ "golang.org/x/text/language"
1518)
1619
1720// ResourceGenerator takes AWS CloudFormation Resource Specification
@@ -138,14 +141,14 @@ func (rg *ResourceGenerator) downloadSpec(location string) ([]byte, error) {
138141 return nil , err
139142 }
140143
141- data , err := ioutil .ReadAll (response .Body )
144+ data , err := io .ReadAll (response .Body )
142145 if err != nil {
143146 return nil , err
144147 }
145148
146149 return data , nil
147150 case "file" :
148- data , err := ioutil .ReadFile (strings .Replace (location , "file://" , "" , - 1 ))
151+ data , err := os .ReadFile (strings .Replace (location , "file://" , "" , - 1 ))
149152 if err != nil {
150153 return nil , err
151154 }
@@ -242,7 +245,7 @@ func (rg *ResourceGenerator) generateAllResourcesMap(resources []GeneratedResour
242245 }
243246
244247 // Write the file contents out
245- if err := ioutil .WriteFile ("cloudformation/all.go" , formatted , 0644 ); err != nil {
248+ if err := os .WriteFile ("cloudformation/all.go" , formatted , 0644 ); err != nil {
246249 return fmt .Errorf ("failed to write Go file for iterable map of all resources: %s" , err )
247250 }
248251
@@ -344,7 +347,7 @@ func (rg *ResourceGenerator) generateResources(name string, resource Resource, i
344347 // Check if the file has changed since the last time generate ran
345348 dir := "cloudformation/" + pname
346349 fn := dir + "/" + filename (name )
347- current , err := ioutil .ReadFile (fn )
350+ current , err := os .ReadFile (fn )
348351
349352 if err != nil || bytes .Compare (formatted , current ) != 0 {
350353
@@ -354,7 +357,7 @@ func (rg *ResourceGenerator) generateResources(name string, resource Resource, i
354357 }
355358
356359 // Write the file contents out
357- if err := ioutil .WriteFile (fn , formatted , 0644 ); err != nil {
360+ if err := os .WriteFile (fn , formatted , 0644 ); err != nil {
358361 return fmt .Errorf ("failed to write resource file %s: %s" , fn , err )
359362 }
360363 // Log the updated resource name to the results
@@ -403,20 +406,20 @@ func (rg *ResourceGenerator) generateJSONSchema(specname string, spec *CloudForm
403406 }
404407
405408 filename := fmt .Sprintf ("schema/%s.schema.json" , specname )
406- if err := ioutil .WriteFile (filename , formatted , 0644 ); err != nil {
409+ if err := os .WriteFile (filename , formatted , 0644 ); err != nil {
407410 return fmt .Errorf ("failed to write JSON Schema: %s" , err )
408411 }
409412
410413 // Also create a Go importable version
411414 var gocode []byte
412415 gocode = append (gocode , []byte ("package schema\n " )... )
413416 gocode = append (gocode , []byte ("\n " )... )
414- gocode = append (gocode , []byte ("// " + strings .Title (specname )+ "Schema defined a JSON Schema that can be used to validate CloudFormation/SAM templates\n " )... )
415- gocode = append (gocode , []byte ("var " + strings .Title (specname )+ "Schema = `" )... )
417+ gocode = append (gocode , []byte ("// " + cases .Title ( language . Und , cases . NoLower ). String (specname )+ "Schema defined a JSON Schema that can be used to validate CloudFormation/SAM templates\n " )... )
418+ gocode = append (gocode , []byte ("var " + cases .Title ( language . Und , cases . NoLower ). String (specname )+ "Schema = `" )... )
416419 gocode = append (gocode , formatted ... )
417420 gocode = append (gocode , []byte ("`\n " )... )
418421 gofilename := fmt .Sprintf ("schema/%s.go" , specname )
419- if err := ioutil .WriteFile (gofilename , gocode , 0644 ); err != nil {
422+ if err := os .WriteFile (gofilename , gocode , 0644 ); err != nil {
420423 return fmt .Errorf ("failed to write Go version of JSON Schema: %s" , err )
421424 }
422425
@@ -430,7 +433,7 @@ func generatePolymorphicProperty(typename string, name string, property Property
430433
431434 // Open the polymorphic property template
432435 tmpl , err := template .New ("polymorphic-property.template" ).Funcs (template.FuncMap {
433- "convertToGoType" : convertTypeToGo ,
436+ "convertToGoType" : convertTypeToGo ,
434437 "convertToPureGoType" : convertTypeToPureGo ,
435438 }).ParseFiles ("generate/templates/polymorphic-property.template" )
436439
@@ -485,7 +488,7 @@ func generatePolymorphicProperty(typename string, name string, property Property
485488 }
486489
487490 // Write the file out
488- if err := ioutil .WriteFile (dir + "/" + filename (name ), formatted , 0644 ); err != nil {
491+ if err := os .WriteFile (dir + "/" + filename (name ), formatted , 0644 ); err != nil {
489492 fmt .Printf ("Error: Failed to write JSON Schema\n %s\n " , err )
490493 os .Exit (1 )
491494 }
0 commit comments