Skip to content

kadai1-shinta #3

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

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

kadai1-shinta #3

wants to merge 7 commits into from

Conversation

ShintaNakama
Copy link

@ShintaNakama ShintaNakama commented Sep 6, 2019

課題1

次の仕様を満たすコマンドを作って下さい

  • ディレクトリを指定する

  • 指定したディレクトリ以下のJPGファイルをPNGに変換(デフォルト)

  • ディレクトリ以下は再帰的に処理する

  • 変換前と変換後の画像形式を指定できる(オプション)

  • 以下を満たすように開発してください

  • mainパッケージと分離する

  • 自作パッケージと標準パッケージと準標準パッケージのみ使う

  • ユーザ定義型を作ってみる

  • GoDocを生成してみる

使い方

# build
go build -o "任意のコマンド名"
# 例
go build -o imgcov
# 実行方法(上記の例の場合)
imgcov [-d=ディレクトリ(default ./), -p=変更対象の拡張子(default jpg), -a=変更後の拡張子(default png)]
# 変換可能な拡張子として、jpg、jpeg、png、gif としています。

スクリーンショット 2019-09-09 1 52 03


// judgeArgExt は引数に設定された拡張子が変換可能なものか判別する
func judgeArgExt(preExt string, afterExt string) (err error) {
allowExtList := []string{"jpg", "jpeg", "png", "gif"}
Copy link
Member

Choose a reason for hiding this comment

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

map[string]boolを使う

}
}
if !judgeExtFlag {
err = errors.New("指定できる拡張子:" + strings.Join(allowExtList, ","))
Copy link
Member

Choose a reason for hiding this comment

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

直接returnする

}

targetImg.Close()
outputImg.Close()
Copy link
Member

Choose a reason for hiding this comment

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

エラー処理


targetImg.Close()
outputImg.Close()
return
Copy link
Member

Choose a reason for hiding this comment

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

不要

*/
func convertImages(dir string, preExt string, afterExt string) (err error) {
// 変換対象ファイルが jpeg or jpg かを確認する
jpgType := [2]string{".jpg", ".jpeg"}
Copy link
Member

Choose a reason for hiding this comment

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

jpgType := map[string]bool{".jpg", ".jpeg"} なら if jpgType[preExt] {} で判断できる

Copy link
Author

Choose a reason for hiding this comment

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

コメントに記載のvalue無しではなく、下記のように宣言するということであってますでしょうか?(missing key in map literal エラーになるので)

jpgType := map[string]bool{".jpg": ture, ".jpeg": true} 

if err != nil {
return err
}
// jpeg は jpgも変換対象とする
Copy link
Member

Choose a reason for hiding this comment

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

以下、すべて対象
jpg -> jpg
jpeg -> jpeg
jpg -> jpeg
jpeg -> jpg

}
return nil
})
return
Copy link
Member

Choose a reason for hiding this comment

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

return errする

func main() {
err := imageconversion.Excute()
if err != nil {
fmt.Fprintln(os.Stderr, err)
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で終了コードを指定する

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants