Skip to content

Commit

Permalink
chore: clean up ioutil deprecated methods. (#118)
Browse files Browse the repository at this point in the history
Signed-off-by: Lan Liang <[email protected]>
  • Loading branch information
liangyuanpeng authored Aug 23, 2024
1 parent 2067204 commit c0d1d0e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/cmds/kcl-openapi.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmds

import (
"io/ioutil"
"io"
"log"
"os"

Expand Down Expand Up @@ -66,7 +66,7 @@ func Main() {
os.Exit(0)
}
opts.Quiet = func() {
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
}
opts.LogFile = func(logfile string) {
f, err := os.OpenFile(logfile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
Expand Down
4 changes: 2 additions & 2 deletions pkg/kube_resource/generator/assets/static/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"bytes"
"fmt"
"go/format"
"io/ioutil"
"os"
"strings"
"unicode"
)
Expand All @@ -26,7 +26,7 @@ func Generate() ([]byte, error) {
fmt.Fprintf(buf, "%v\n\n%v\n\npackage static\n\n", license, warning)
fmt.Fprintf(buf, "var Files = map[string]string{\n")
for _, fn := range files {
b, err := ioutil.ReadFile(fn)
b, err := os.ReadFile(fn)
if err != nil {
return b, err
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/kube_resource/generator/assets/static/makestatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"

"kcl-lang.io/kcl-openapi/pkg/kube_resource/generator/assets/static"
Expand All @@ -29,7 +28,7 @@ func makestatic() error {
if err != nil {
return fmt.Errorf("error while generating static.go: %v\n", err)
}
err = ioutil.WriteFile("static.go", buf, 0666)
err = os.WriteFile("static.go", buf, 0666)
if err != nil {
return fmt.Errorf("error while writing static.go: %v\n", err)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/swagger/generator/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"path"
Expand Down Expand Up @@ -292,7 +291,7 @@ func (g *GenOpts) write(t *TemplateOpts, data interface{}) error {
formatted, err = g.LanguageOpts.FormatContent(filepath.Join(dir, fname), content)
if err != nil {
log.Printf("source formatting failed on template-generated source (%q for %s). Check that your template produces valid code", filepath.Join(dir, fname), t.Name)
writeerr = ioutil.WriteFile(filepath.Join(dir, fname), content, 0644)
writeerr = os.WriteFile(filepath.Join(dir, fname), content, 0644)
if writeerr != nil {
return fmt.Errorf("failed to write (unformatted) file %q in %q: %v", fname, dir, writeerr)
}
Expand All @@ -301,7 +300,7 @@ func (g *GenOpts) write(t *TemplateOpts, data interface{}) error {
}
}

writeerr = ioutil.WriteFile(filepath.Join(dir, fname), formatted, 0644)
writeerr = os.WriteFile(filepath.Join(dir, fname), formatted, 0644)
if writeerr != nil {
return fmt.Errorf("failed to write file %q in %q: %v", fname, dir, writeerr)
}
Expand Down

0 comments on commit c0d1d0e

Please sign in to comment.