・・・・ type iScanner interface { Err() error Scan() bool Text() string } func ifuncNewScanner(r io.Reader) iScanner { return bufio.NewScanner(r) } type hookBufio struct { NewScanner func(r io.Reader) iScanner } type iFile interface { Close() error WriteString(s string) (n int, err error) Read(p []byte) (n int, err error) } func ifuncOpen(name string) (iFile, error) { return os.Open(name) } func ifuncCreate(name string) (iFile, error) { return os.Create(name) } type hookOs struct { Open func(name string) (iFile, error) Create func(name string) (iFile, error) } type hook struct { bufio *hookBufio os *hookOs } // textLines はテキストを格納します。 // [TODO] 文字エンコーディング関係機能 type textLines struct { // 文字列スライス lines []string // フック hook *hook } ・・・・ func (t *textLines) LoadFrom(filename string) error { f, err := t.hook.os.Open(filename) if err != nil { return fmt.Errorf("os.Open(%s) return %v", filename, err) } defer f.Close() s := t.hook.bufio.NewScanner(f) for s.Scan() { t.lines = append(t.lines, s.Text()) } err = s.Err() if err != nil { return fmt.Errorf("scanner.Scan(%s) return %v", filename, err) } return err }