nettools/io/io.go
2024-11-12 09:10:09 +01:00

26 lines
467 B
Go

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
}