Open
Conversation
tenntenn
reviewed
Jul 31, 2019
| ) | ||
|
|
||
| // IConverter コンバーターインターフェース | ||
| type IConverter interface { |
tenntenn
reviewed
Jul 31, 2019
|
|
||
| // IConverter コンバーターインターフェース | ||
| type IConverter interface { | ||
| convert(file *os.File, img image.Image) error |
Member
There was a problem hiding this comment.
型名がexportされているのにメソッド名がexportされていない理由は?
tenntenn
reviewed
Jul 31, 2019
| ) | ||
|
|
||
| // Validate フィールドのバリデーション処理を行う. | ||
| func (c converter) validate() bool { |
Member
There was a problem hiding this comment.
構造体の場合、特に理由がない場合はレシーバにはポインタを使う。
https://qiita.com/knsh14/items/8b73b31822c109d4c497#receiver-type
tenntenn
reviewed
Jul 31, 2019
| return validate(c.src) && validate(c.dst) | ||
| } | ||
|
|
||
| func validate(ext string) bool { |
tenntenn
reviewed
Jul 31, 2019
| } | ||
|
|
||
| func validate(ext string) bool { | ||
| for _, e := range convertibleExts { |
Member
There was a problem hiding this comment.
mapを使えば関数不要そう。
https://play.golang.org/p/11bEbuN1BLW
tenntenn
reviewed
Jul 31, 2019
|
|
||
| src, err := os.Open(path) | ||
| if err != nil { | ||
| log.Fatalf("Faild to open file. err = %v\n", err) |
Member
There was a problem hiding this comment.
log.Fatalは中でos.Exitを呼び出すので基本的にmain関数以外では使わない。
errorを返す。
main関数であってもox.Exitに渡す終了コードを指定することができないため、基本的には使わない。
tenntenn
reviewed
Jul 31, 2019
| if err != nil { | ||
| log.Fatalf("Faild to create file. err = %v\n", err) | ||
| } | ||
| defer dst.Close() |
tenntenn
reviewed
Jul 31, 2019
| switch dst { | ||
| case "png": | ||
| return pngConverter{c} | ||
| case "jpeg": |
tenntenn
reviewed
Jul 31, 2019
| } | ||
|
|
||
| // GetConverter 拡張子に対応したコンバーターを取得する. | ||
| func GetConverter(src, dst string) IConverter { |
tenntenn
reviewed
Jul 31, 2019
| "testing" | ||
| ) | ||
|
|
||
| func TestGetConverter(t *testing.T) { |
tenntenn
reviewed
Jul 31, 2019
| func TestGetConverter(t *testing.T) { | ||
| var c IConverter | ||
| c = GetConverter("jpeg", "png") | ||
| if _, ok := c.(pngConverter); !ok { |
Member
There was a problem hiding this comment.
せっかくインタフェースにしているのに、テストが具体的な実装に依存しているのはあまりよくない。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1回目の宿題のテストを作ってみて下さい
テーブル駆動テストを導入しました。
テストヘルパーの作成はまだできていません。
io.Readerとio.Writerについて調べてみよう
byte型のスライスを引数に取り、pに値を読み込む。
読み込んだバイト数とエラーを返す。
byte型のスライスを引数に取り、pから値を書き込む。
書き込んだバイト数とエラーを返す。
上記のように様々な箇所での読み書きに使用されていた。
また、以下のようなerrorの戻り値を利用するような使い方も見られた。