-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: master
Are you sure you want to change the base?
Conversation
|
||
// judgeArgExt は引数に設定された拡張子が変換可能なものか判別する | ||
func judgeArgExt(preExt string, afterExt string) (err error) { | ||
allowExtList := []string{"jpg", "jpeg", "png", "gif"} |
There was a problem hiding this comment.
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, ",")) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"} |
There was a problem hiding this comment.
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] {}
で判断できる
There was a problem hiding this comment.
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も変換対象とする |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os.Exitで終了コードを指定する
課題1
次の仕様を満たすコマンドを作って下さい
ディレクトリを指定する
指定したディレクトリ以下のJPGファイルをPNGに変換(デフォルト)
ディレクトリ以下は再帰的に処理する
変換前と変換後の画像形式を指定できる(オプション)
以下を満たすように開発してください
mainパッケージと分離する
自作パッケージと標準パッケージと準標準パッケージのみ使う
ユーザ定義型を作ってみる
GoDocを生成してみる
使い方