-
Notifications
You must be signed in to change notification settings - Fork 7
kadai1: make image converter #1
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
ext := filepath.Ext(path) | ||
var err error | ||
err = func(ext string) error { | ||
for _, postfix := range []string{".jpeg", ".jpg", ".gif", ".png"} { |
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.
IMHO: postfixは間違いではありませんが、suffixのほうがより伝わりやすいかもしれません。ご参考
(同名のメールサーバがありますので、ちょっと気になっちゃいました)
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.
たしかにおっしゃる通り...、ご指摘ありがとうございます!
} | ||
|
||
// Replace replace image | ||
func (i *Img) Replace(ext string) error { |
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.
メソッド名から処理(画像変換)を想像できないかもです。Convert(ext string, removeOldFile bool)
などいかがでしょうか?
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.
これもたしかにおっしゃる通りですね...!
kadai1/sh-tatsuno/gophoto/main.go
Outdated
var dirName, input, output string | ||
|
||
// args | ||
flags := flag.NewFlagSet("imgconv", flag.ContinueOnError) |
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.
本質的でない細かなコメントなのですが、”imgconv” のリテラルは os.Args[0]
で表現した方がより再利用性が高まると思います。
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.
なるほど...!ご指摘ありがとうございます!
|
||
import ( | ||
"image" | ||
"image/gif" // import 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.
コメントがコードから分かる以上の情報がないんですがコメントを残した理由はなんでしょうか?
) | ||
|
||
// Img image struct | ||
type Img struct { |
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.
略さない
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.
Pathと画像自体の情報を持ったものがImg
で良いのか?
} | ||
|
||
// NewImg generate Img struct | ||
func NewImg(path string) (*Img, error) { |
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.
Img
構造体を作ること以上のことをやっている。
} | ||
|
||
// Save save img for input format if format satisfies ".jpeg", ".jpg", ".gif", ".png" | ||
func (i *Img) Save(path string) error { |
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.
せっかくフィールドにPath
を持っているのになぜ引数で渡すのか?
func (i *Img) Save(path string) error { | ||
ext := filepath.Ext(path) | ||
var err error | ||
err = func(ext string) error { |
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.
クロージャ内で参照しないのであれば、err := ...
でよい。
|
||
const ( | ||
// ExitCodeOK : exit code | ||
ExitCodeOK = iota |
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.
外部に出る値でiota
を使うのはあまりよくない。
順番が変わったり間に増えたら値が変わる。
|
||
if dirName == "" { | ||
usage() | ||
fmt.Printf("Expected dir path\n") |
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.Stdout
に出さない
var pathList []string | ||
pathList, err := dir.Lookup(dirName, input, pathList) | ||
if err != nil { | ||
fmt.Printf("can not open file, %v\n", 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.Stdout
に出さない
} | ||
|
||
// lookup | ||
var pathList []string |
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.
変数定義せずに[]string{}
のようなリテラルを引数に渡したほうがわかりやすい。
} | ||
|
||
if err := img.Convert(output); err != nil { | ||
fmt.Printf("can not convert file, %v\n", 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.Stdout
に出さない。
I have implemented go-converter called "go photo".
It would be appreciated if you review my code.
The points especially I want to check