Skip to content

hiroygo / 課題1 - #7

Draft
hiroygo wants to merge 7 commits into
masterfrom
kadai1-hiroygo
Draft

hiroygo / 課題1#7
hiroygo wants to merge 7 commits into
masterfrom
kadai1-hiroygo

Conversation

@hiroygo

@hiroygo hiroygo commented Jul 7, 2020

Copy link
Copy Markdown
Member

課題1のPRになります。
お忙しいところ、すみませんが
レビューをよろしくお願いいたします。

@hiroygo
hiroygo requested a review from tenntenn July 8, 2020 13:07
@tenntenn tenntenn added the kadai1 課題1 label Jul 9, 2020

@tenntenn tenntenn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

見ました!

// Unknown 不明な画像
Unknown ImageType = "unknown"
// Jpeg Jpeg 画像
Jpeg ImageType = "jpg"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

略語はすべて大文字または小文字で

// ToImageType 文字列を ImageType に変換する
// e.g. "jpg" => Jpeg
func ToImageType(s string) ImageType {
switch s {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings.ToLowerを使っても良いかもしれないですね。
https://golang.org/pkg/strings/#ToLower

}

func imageTypeFromFileName(name string) ImageType {
extWithoutDot := strings.TrimLeft(filepath.Ext(name), ".")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このくらいであればスライス演算でもいいかもしれないです。


func imageTypeFromFileName(name string) ImageType {
extWithoutDot := strings.TrimLeft(filepath.Ext(name), ".")
return ToImageType(strings.ToLower(extWithoutDot))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでToLowerするより、ToImageTypeの内部でやったほうが使う側の手間が省けます。

var pathes []string
err := filepath.Walk(dir, func(visitPath string, f os.FileInfo, err error) error {
if err != nil {
return fmt.Errorf("WalkFunc error, %w", err)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread kadai1/hiroygo/main.go
)

func parseArgs() (dir string, in, out imgconv.ImageType, err error) {
d := flag.String("d", "./", "変換の対象となる画像が格納されたディレクトリパス")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/は含めずに.で良いと思います。Windowsは\なので。

Comment thread kadai1/hiroygo/main.go
dir, inType, outType, err := parseArgs()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.Exitで0以外で終了したほうが良いでしょう。

@tenntenn tenntenn added the reviewed レビュー済 label Jul 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kadai1 課題1 reviewed レビュー済

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants