FILE / ScuroNeko/mtg

ipblocklist/files/local.go

Исходный файл и его история в репозитории.
FILE 01e201365b076c4727d5d0300e048304f9faba83
Files
mtg/ipblocklist/files/local.go
T
2021-11-29 16:25:33 +03:00

31 lines
522 B
Go

package files
import (
"context"
"fmt"
"io"
"os"
)
type localFile struct {
path string
}
func (l localFile) Open(ctx context.Context) (io.ReadCloser, error) {
return os.Open(l.path) // nolint: wrapcheck
}
func (l localFile) String() string {
return l.path
}
func NewLocal(path string) (File, error) {
if stat, err := os.Stat(path); os.IsNotExist(err) || stat.IsDir() || stat.Mode().Perm()&0o400 == 0 {
return nil, fmt.Errorf("%s is not a readable file", path)
}
return localFile{
path: path,
}, nil
}