Go: 标准库 os
提供跨平台的操作系统功能接口
Go 的 os 包提供跨平台的操作系统功能接口,设计风格类 Unix,错误处理用 Go 惯用的 error 类型。
核心功能围绕着文件、目录、进程、环境变量、元数据等...
文件
文件实现了Go: 标准库 io的接口:
// go doc os.File
type File struct{}
func (f *File) Read(b []byte) (n int, err error)
func (f *File) ReadAt(b []byte, off int64) (n int, err error)
func (f *File) ReadFrom(r io.Reader) (n int64, err error)
func (f *File) Write(b []byte) (n int, err error)
func (f *File) WriteAt(b []byte, off int64) (n int, err error)
func (f *File) WriteTo(w io.Writer) (n int64, err error)
func (f *File) Close() error
func (f *File) Seek(offset int64, whence int) (ret int64, err error)
// 其他IO定义的接口...也实现了Go: 标准库 io/fs的接口;
// 实现了 fs.File 接口
func (f *File) Stat() (FileInfo, error)
// io.Reader io.Closer
// func (f *File) Read(b []byte) (n int, err error)
// func (f *File) Close() error
// 实现了 fs.FileInfo 接口
type fileStat struct{}进程
go doc os.Process
评论