Skip to content

kadai1_gashiura#3

Open
gashiura wants to merge 1 commit intomasterfrom
kadai1-gashiura
Open

kadai1_gashiura#3
gashiura wants to merge 1 commit intomasterfrom
kadai1-gashiura

Conversation

@gashiura
Copy link

@gashiura gashiura commented May 31, 2019

仕様

  • src/main.goがエントリポイント。
  • 画像形式はjpeg, png, gifに対応。
  • コマンド実行時の引数にルートディレクトリ、オプションに画像形式を指定。

使い方

main.go -s png -d gif .

引数: ルートディレクトリを指定
-sオプション: 変換元の画像形式。jpeg, png, gifに対応。 デフォルト値:jpeg
-dオプション: 変換先の画像形式。jpeg, png, gifに対応。 デフォルト値:png

見ていただきたい点

  • golang的にもっと簡潔にかける部分があるか見ていただきたいです。
  • エラー処理のコードで、重複している箇所があるので、実務で使う時うまくまとめる方法があれば教えていただきたいです。
  • packageの分け方がよく分からず悩んだので、実務で気を付けている点があれば教えていただきたいです。

func Valid(s, d string) error {
r := regexp.MustCompile("^(jpeg|png|gif)$")
if !r.MatchString(s) || !r.MatchString(d) {
return errors.New("please set \"jpeg\" or \"png\" or \"gif\" as an option.")
Copy link

Choose a reason for hiding this comment

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

ご提案: バッククオートで囲むとエスケープなしで書けます!

return errors.New(`please set "jpeg" or "png" or "gif" as an option.`)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants