/
abatalev
/
gitdiff2fly
Обзор
Документация
Войти
/
abatalev
/
gitdiff2fly
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
fs.go
49 строк
818 B
andrey
replace calls to the ReadFile and WriteFile functions from the io/ioutil package with functions from the os package
01 окт 2023, 13:44
01 окт 2023, 13:44
aa67190
Код
Авторство
О чём код?
package main import ( "fmt" "io" "os" "strings" ) type fsInterface interface { copy(src string, dst string) error readFile(fileName string) []string } type OsSystem struct { } func (osx *OsSystem) readFile(fileName string) []string { content, err := os.ReadFile(fileName) if err != nil { panic(err) } return strings.Split(string(content), "\n") } func (osx *OsSystem) copy(src, dst string) error { sourceFileStat, err := os.Stat(src) if err != nil { return err } if !sourceFileStat.Mode().IsRegular() { return fmt.Errorf("%s is not a regular file", src) } source, err := os.Open(src) if err != nil { return err } defer source.Close() destination, err := os.Create(dst) if err != nil { return err } defer destination.Close() _, err = io.Copy(destination, source) return err }