Add 'environment' package
This commit adds a new environment package that manages all calls to the underlying operating system.
This commit is contained in:
parent
822c70cd69
commit
f19619ef9f
60 changed files with 539 additions and 308 deletions
58
pkg/environment/environment.go
Normal file
58
pkg/environment/environment.go
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
package environment
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/fs"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
// Environment represents an environment that a program can run it.
|
||||
// It mostly mimics the interfaces of the [os] package.
|
||||
type Environment interface {
|
||||
isEnv()
|
||||
|
||||
GetEnv(name string) string
|
||||
|
||||
Stat(path string) (fs.FileInfo, error)
|
||||
Lstat(path string) (fs.FileInfo, error)
|
||||
|
||||
Readlink(path string) (string, error)
|
||||
Symlink(oldname, newname string) error
|
||||
|
||||
ReadDir(name string) ([]fs.DirEntry, error)
|
||||
|
||||
Open(path string) (fs.File, error)
|
||||
Chtimes(name string, atime time.Time, mtime time.Time) error
|
||||
SameFile(f1, f2 fs.FileInfo) bool
|
||||
|
||||
Create(path string, mode fs.FileMode) (WritableFile, error)
|
||||
|
||||
Mkdir(path string, mode fs.FileMode) error
|
||||
MkdirAll(path string, mode fs.FileMode) error
|
||||
|
||||
Remove(path string) error
|
||||
RemoveAll(path string) error
|
||||
|
||||
WalkDir(root string, fn fs.WalkDirFunc) error
|
||||
|
||||
Abs(path string) (string, error)
|
||||
|
||||
Listen(network, address string) (net.Listener, error)
|
||||
Dial(network, address string) (net.Conn, error)
|
||||
|
||||
Executable() (string, error)
|
||||
Exec(io stream.IOStream, workdir string, exe string, argv ...string) int
|
||||
LookPathAbs(name string) (string, error)
|
||||
}
|
||||
|
||||
type WritableFile interface {
|
||||
fs.File
|
||||
io.Writer
|
||||
}
|
||||
|
||||
func init() {
|
||||
var _ Environment = Native{}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue