nettools/io/io.go

26 lines
467 B
Go
Raw Permalink Normal View History

2024-11-12 08:10:09 +00:00
package io_utils
import (
"errors"
"os"
)
var (
ErrReadingFile = errors.New("error while reading the file")
ErrFileEmpty = errors.New("provided file is empty")
)
func ReadPassFile(path string) (pass string, err error) {
buff, err := os.ReadFile(path)
if err != nil {
return "", errors.Join(ErrReadingFile, err)
}
if len(buff) < 1 {
return "", ErrFileEmpty
}
if buff[len(buff)-1] == '\n' {
buff = buff[:len(buff)-1]
}
return string(buff), nil
}