Skip to content

Commit 9c60bc1

Browse files
committed
update
1 parent a3839fb commit 9c60bc1

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

Diff for: kadai2/tanaka0325/imgconv/cmd/imgconv/main.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ func main() {
4040
// convert
4141
for _, path := range paths {
4242
param := imgconv.ConvertParam{
43-
File: imgconv.NewFile(path),
43+
Path: path,
44+
File: imgconv.NewFile(),
4445
BeforeImage: imgconv.NewImage(*options.From),
4546
AfterImage: imgconv.NewImage(*options.To),
4647
FromExt: *options.From,
@@ -52,7 +53,7 @@ func main() {
5253
onExit(err)
5354
}
5455
} else {
55-
fmt.Printf("%[1]s.%[2]s => %[1]s.%[3]s\n", param.File.GetPath(), param.FromExt, param.ToExt)
56+
fmt.Printf("%[1]s.%[2]s => %[1]s.%[3]s\n", path, param.FromExt, param.ToExt)
5657
}
5758
}
5859
}

Diff for: kadai2/tanaka0325/imgconv/file.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ import (
66
)
77

88
type OpenCreator interface {
9-
Open() (io.ReadCloser, error)
10-
Create() (io.WriteCloser, error)
11-
GetPath() string
9+
Open(string) (io.ReadCloser, error)
10+
Create(string) (io.WriteCloser, error)
1211
}
1312

1413
type File struct {
15-
Path string
1614
}
1715

18-
func (f *File) Open() (io.ReadCloser, error) { return os.Open(f.Path) }
19-
func (f *File) Create() (io.WriteCloser, error) { return os.Create(f.Path) }
20-
func (f *File) GetPath() string { return f.Path }
16+
func (f *File) Open(n string) (io.ReadCloser, error) { return os.Open(n) }
17+
func (f *File) Create(n string) (io.WriteCloser, error) { return os.Create(n) }
2118

22-
func NewFile(p string) *File {
23-
return &File{Path: p}
19+
func NewFile() *File {
20+
return &File{}
2421
}

Diff for: kadai2/tanaka0325/imgconv/imgconv.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package imgconv
33

44
type ConvertParam struct {
5+
Path string
56
File OpenCreator
67
BeforeImage Decoder
78
AfterImage Encoder
@@ -11,7 +12,7 @@ type ConvertParam struct {
1112

1213
func Do(param ConvertParam) (err error) {
1314
// open file
14-
r, err := param.File.Open()
15+
r, err := param.File.Open(param.Path + "." + param.FromExt)
1516
if err != nil {
1617
return
1718
}
@@ -24,7 +25,7 @@ func Do(param ConvertParam) (err error) {
2425
}
2526

2627
// create file
27-
w, err := param.File.Create()
28+
w, err := param.File.Create(param.Path + "." + param.ToExt)
2829
if err != nil {
2930
return err
3031
}

0 commit comments

Comments
 (0)