Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hiroygo / 課題1 #7

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft

hiroygo / 課題1 #7

wants to merge 7 commits into from

Conversation

hiroygo
Copy link
Member

@hiroygo hiroygo commented Jul 7, 2020

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

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

@tenntenn tenntenn left a comment

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
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
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
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
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
Member

Choose a reason for hiding this comment

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

👍

)

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

Choose a reason for hiding this comment

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

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

dir, inType, outType, err := parseArgs()
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
Copy link
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