type Signal(interface)
A Signal represents an operating system signal.
The usual underlying implementation is operating system-dependent:
on Unix it is syscall.Signal.
(T) Signal()
(T) String() string
syscall.Signal
T : fmt.Stringer
func (*Process).Signal(sig Signal) error
var Interrupt
var Kill
var Args []string
Args hold the command-line arguments, starting with the program name.
func Chdir(dir string) error
Chdir changes the current working directory to the named directory.
If there is an error, it will be of type *PathError.
func Chmod(name string, mode FileMode) error
Chmod changes the mode of the named file to mode.
If the file is a symbolic link, it changes the mode of the link's target.
If there is an error, it will be of type *PathError.
A different subset of the mode bits are used, depending on the
operating system.
On Unix, the mode's permission bits, ModeSetuid, ModeSetgid, and
ModeSticky are used.
On Windows, only the 0200 bit (owner writable) of mode is used; it
controls whether the file's read-only attribute is set or cleared.
The other bits are currently unused. For compatibility with Go 1.12
and earlier, use a non-zero mode. Use mode 0400 for a read-only
file and 0600 for a readable+writable file.
On Plan 9, the mode's permission bits, ModeAppend, ModeExclusive,
and ModeTemporary are used.
func Chown(name string, uid, gid int) error
Chown changes the numeric uid and gid of the named file.
If the file is a symbolic link, it changes the uid and gid of the link's target.
A uid or gid of -1 means to not change that value.
If there is an error, it will be of type *PathError.
On Windows or Plan 9, Chown always returns the syscall.EWINDOWS or
EPLAN9 error, wrapped in *PathError.
func Chtimes(name string, atime time.Time, mtime time.Time) error
Chtimes changes the access and modification times of the named
file, similar to the Unix utime() or utimes() functions.
The underlying filesystem may truncate or round the values to a
less precise time unit.
If there is an error, it will be of type *PathError.
func Clearenv()
Clearenv deletes all environment variables.
func Create(name string) (*File, error)
Create creates or truncates the named file. If the file already exists,
it is truncated. If the file does not exist, it is created with mode 0666
(before umask). If successful, methods on the returned File can
be used for I/O; the associated file descriptor has mode O_RDWR.
If there is an error, it will be of type *PathError.
const DevNull = "/dev/null"
DevNull is the name of the operating system's ``null device.''
On Unix-like systems, it is "/dev/null"; on Windows, "NUL".
func Environ() []string
Environ returns a copy of strings representing the environment,
in the form "key=value".
var ErrClosederror // "file already closed"
Portable analogs of some common system call errors.
Errors returned from this package may be tested against these errors
with errors.Is.
var ErrDeadlineExceedederror // "i/o timeout"
Portable analogs of some common system call errors.
Errors returned from this package may be tested against these errors
with errors.Is.
var ErrExisterror // "file already exists"
Portable analogs of some common system call errors.
Errors returned from this package may be tested against these errors
with errors.Is.
var ErrInvaliderror // "invalid argument"
ErrInvalid indicates an invalid argument.
Methods on File will return this error when the receiver is nil.
var ErrNoDeadlineerror // "file type does not support deadline"
Portable analogs of some common system call errors.
Errors returned from this package may be tested against these errors
with errors.Is.
var ErrNotExisterror // "file does not exist"
Portable analogs of some common system call errors.
Errors returned from this package may be tested against these errors
with errors.Is.
var ErrPermissionerror // "permission denied"
Portable analogs of some common system call errors.
Errors returned from this package may be tested against these errors
with errors.Is.
func Executable() (string, error)
Executable returns the path name for the executable that started
the current process. There is no guarantee that the path is still
pointing to the correct executable. If a symlink was used to start
the process, depending on the operating system, the result might
be the symlink or the path it pointed to. If a stable result is
needed, path/filepath.EvalSymlinks might help.
Executable returns an absolute path unless an error occurred.
The main use case is finding resources located relative to an
executable.
func Exit(code int)
Exit causes the current program to exit with the given status code.
Conventionally, code zero indicates success, non-zero an error.
The program terminates immediately; deferred functions are not run.
For portability, the status code should be in the range [0, 125].
func Expand(s string, mapping func(string) string) string
Expand replaces ${var} or $var in the string based on the mapping function.
For example, os.ExpandEnv(s) is equivalent to os.Expand(s, os.Getenv).
func ExpandEnv(s string) string
ExpandEnv replaces ${var} or $var in the string according to the values
of the current environment variables. References to undefined
variables are replaced by the empty string.
func FindProcess(pid int) (*Process, error)
FindProcess looks for a running process by its pid.
The Process it returns can be used to obtain information
about the underlying operating system process.
On Unix systems, FindProcess always succeeds and returns a Process
for the given pid, regardless of whether the process exists.
func Getegid() int
Getegid returns the numeric effective group id of the caller.
On Windows, it returns -1.
func Getenv(key string) string
Getenv retrieves the value of the environment variable named by the key.
It returns the value, which will be empty if the variable is not present.
To distinguish between an empty value and an unset value, use LookupEnv.
func Geteuid() int
Geteuid returns the numeric effective user id of the caller.
On Windows, it returns -1.
func Getgid() int
Getgid returns the numeric group id of the caller.
On Windows, it returns -1.
func Getgroups() ([]int, error)
Getgroups returns a list of the numeric ids of groups that the caller belongs to.
On Windows, it returns syscall.EWINDOWS. See the os/user package
for a possible alternative.
func Getpagesize() int
Getpagesize returns the underlying system's memory page size.
func Getpid() int
Getpid returns the process id of the caller.
func Getppid() int
Getppid returns the process id of the caller's parent.
func Getuid() int
Getuid returns the numeric user id of the caller.
On Windows, it returns -1.
func Getwd() (dir string, err error)
Getwd returns a rooted path name corresponding to the
current directory. If the current directory can be
reached via multiple paths (due to symbolic links),
Getwd may return any one of them.
func Hostname() (name string, err error)
Hostname returns the host name reported by the kernel.
var InterruptSignal
The only signal values guaranteed to be present in the os package on all
systems are os.Interrupt (send the process an interrupt) and os.Kill (force
the process to exit). On Windows, sending os.Interrupt to a process with
os.Process.Signal is not implemented; it will return an error instead of
sending a signal.
func IsExist(err error) bool
IsExist returns a boolean indicating whether the error is known to report
that a file or directory already exists. It is satisfied by ErrExist as
well as some syscall errors.
func IsNotExist(err error) bool
IsNotExist returns a boolean indicating whether the error is known to
report that a file or directory does not exist. It is satisfied by
ErrNotExist as well as some syscall errors.
func IsPathSeparator(c uint8) bool
IsPathSeparator reports whether c is a directory separator character.
func IsPermission(err error) bool
IsPermission returns a boolean indicating whether the error is known to
report that permission is denied. It is satisfied by ErrPermission as well
as some syscall errors.
func IsTimeout(err error) bool
IsTimeout returns a boolean indicating whether the error is known
to report that a timeout occurred.
var KillSignal
The only signal values guaranteed to be present in the os package on all
systems are os.Interrupt (send the process an interrupt) and os.Kill (force
the process to exit). On Windows, sending os.Interrupt to a process with
os.Process.Signal is not implemented; it will return an error instead of
sending a signal.
func Lchown(name string, uid, gid int) error
Lchown changes the numeric uid and gid of the named file.
If the file is a symbolic link, it changes the uid and gid of the link itself.
If there is an error, it will be of type *PathError.
On Windows, it always returns the syscall.EWINDOWS error, wrapped
in *PathError.
func Link(oldname, newname string) error
Link creates newname as a hard link to the oldname file.
If there is an error, it will be of type *LinkError.
func LookupEnv(key string) (string, bool)
LookupEnv retrieves the value of the environment variable named
by the key. If the variable is present in the environment the
value (which may be empty) is returned and the boolean is true.
Otherwise the returned value will be empty and the boolean will
be false.
func Lstat(name string) (FileInfo, error)
Lstat returns a FileInfo describing the named file.
If the file is a symbolic link, the returned FileInfo
describes the symbolic link. Lstat makes no attempt to follow the link.
If there is an error, it will be of type *PathError.
func Mkdir(name string, perm FileMode) error
Mkdir creates a new directory with the specified name and permission
bits (before umask).
If there is an error, it will be of type *PathError.
func MkdirAll(path string, perm FileMode) error
MkdirAll creates a directory named path,
along with any necessary parents, and returns nil,
or else returns an error.
The permission bits perm (before umask) are used for all
directories that MkdirAll creates.
If path is already a directory, MkdirAll does nothing
and returns nil.
const ModeAppendFileMode = 1073741824 // a: append-only
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeCharDeviceFileMode = 2097152 // c: Unix character device, when ModeDevice is set
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeDeviceFileMode = 67108864 // D: device file
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeDirFileMode = 2147483648 // d: is a directory
The single letters are the abbreviations
used by the String method's formatting.
const ModeExclusiveFileMode = 536870912 // l: exclusive use
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeIrregularFileMode = 524288 // ?: non-regular file; nothing else is known about this file
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeNamedPipeFileMode = 33554432 // p: named pipe (FIFO)
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModePermFileMode = 511 // Unix permission bits
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeSetgidFileMode = 4194304 // g: setgid
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeSetuidFileMode = 8388608 // u: setuid
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeSocketFileMode = 16777216 // S: Unix domain socket
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeStickyFileMode = 1048576 // t: sticky
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeSymlinkFileMode = 134217728 // L: symbolic link
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeTemporaryFileMode = 268435456 // T: temporary file; Plan 9 only
The defined file mode bits are the most significant bits of the FileMode.
The nine least-significant bits are the standard Unix rwxrwxrwx permissions.
The values of these bits should be considered part of the public API and
may be used in wire protocols or disk representations: they must not be
changed, although new bits might be added.
const ModeTypeFileMode = 2401763328
Mask for the type bits. For regular files, none will be set.
func NewFile(fd uintptr, name string) *File
NewFile returns a new File with the given file descriptor and
name. The returned value will be nil if fd is not a valid file
descriptor. On Unix systems, if the file descriptor is in
non-blocking mode, NewFile will attempt to return a pollable File
(one for which the SetDeadline methods work).
func NewSyscallError(syscall string, err error) error
NewSyscallError returns, as an error, a new SyscallError
with the given system call name and error details.
As a convenience, if err is nil, NewSyscallError returns nil.
const O_APPENDint = 8 // append data to the file when writing.
The remaining values may be or'ed in to control behavior.
const O_CREATEint = 512 // create a new file if none exists.
Flags to OpenFile wrapping those of the underlying system. Not all
flags may be implemented on a given system.
const O_EXCLint = 2048 // used with O_CREATE, file must not exist.
Flags to OpenFile wrapping those of the underlying system. Not all
flags may be implemented on a given system.
const O_RDONLYint = 0 // open the file read-only.
Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified.
const O_RDWRint = 2 // open the file read-write.
Flags to OpenFile wrapping those of the underlying system. Not all
flags may be implemented on a given system.
const O_SYNCint = 128 // open for synchronous I/O.
Flags to OpenFile wrapping those of the underlying system. Not all
flags may be implemented on a given system.
const O_TRUNCint = 1024 // truncate regular writable file when opened.
Flags to OpenFile wrapping those of the underlying system. Not all
flags may be implemented on a given system.
const O_WRONLYint = 1 // open the file write-only.
Flags to OpenFile wrapping those of the underlying system. Not all
flags may be implemented on a given system.
func Open(name string) (*File, error)
Open opens the named file for reading. If successful, methods on
the returned file can be used for reading; the associated file
descriptor has mode O_RDONLY.
If there is an error, it will be of type *PathError.
func OpenFile(name string, flag int, perm FileMode) (*File, error)
OpenFile is the generalized open call; most users will use Open
or Create instead. It opens the named file with specified flag
(O_RDONLY etc.). If the file does not exist, and the O_CREATE flag
is passed, it is created with mode perm (before umask). If successful,
methods on the returned File can be used for I/O.
If there is an error, it will be of type *PathError.
func Pipe() (r *File, w *File, err error)
Pipe returns a connected pair of Files; reads from r return bytes written to w.
It returns the files and an error, if any.
func Readlink(name string) (string, error)
Readlink returns the destination of the named symbolic link.
If there is an error, it will be of type *PathError.
func Remove(name string) error
Remove removes the named file or (empty) directory.
If there is an error, it will be of type *PathError.
func RemoveAll(path string) error
RemoveAll removes path and any children it contains.
It removes everything it can but returns the first error
it encounters. If the path does not exist, RemoveAll
returns nil (no error).
If there is an error, it will be of type *PathError.
func Rename(oldpath, newpath string) error
Rename renames (moves) oldpath to newpath.
If newpath already exists and is not a directory, Rename replaces it.
OS-specific restrictions may apply when oldpath and newpath are in different directories.
If there is an error, it will be of type *LinkError.
func SameFile(fi1, fi2 FileInfo) bool
SameFile reports whether fi1 and fi2 describe the same file.
For example, on Unix this means that the device and inode fields
of the two underlying structures are identical; on other systems
the decision may be based on the path names.
SameFile only applies to results returned by this package's Stat.
It returns false in other cases.
const SEEK_CURint = 1 // seek relative to the current offset
Seek whence values.
Deprecated: Use io.SeekStart, io.SeekCurrent, and io.SeekEnd.
const SEEK_ENDint = 2 // seek relative to the end
Seek whence values.
Deprecated: Use io.SeekStart, io.SeekCurrent, and io.SeekEnd.
const SEEK_SETint = 0 // seek relative to the origin of the file
Seek whence values.
Deprecated: Use io.SeekStart, io.SeekCurrent, and io.SeekEnd.
func Setenv(key, value string) error
Setenv sets the value of the environment variable named by the key.
It returns an error, if any.
func StartProcess(name string, argv []string, attr *ProcAttr) (*Process, error)
StartProcess starts a new process with the program, arguments and attributes
specified by name, argv and attr. The argv slice will become os.Args in the
new process, so it normally starts with the program name.
If the calling goroutine has locked the operating system thread
with runtime.LockOSThread and modified any inheritable OS-level
thread state (for example, Linux or Plan 9 name spaces), the new
process will inherit the caller's thread state.
StartProcess is a low-level interface. The os/exec package provides
higher-level interfaces.
If there is an error, it will be of type *PathError.
func Stat(name string) (FileInfo, error)
Stat returns a FileInfo describing the named file.
If there is an error, it will be of type *PathError.
var Stderr *File
Stdin, Stdout, and Stderr are open Files pointing to the standard input,
standard output, and standard error file descriptors.
Note that the Go runtime writes to standard error for panics and crashes;
closing Stderr may cause those messages to go elsewhere, perhaps
to a file opened later.
var Stdin *File
Stdin, Stdout, and Stderr are open Files pointing to the standard input,
standard output, and standard error file descriptors.
Note that the Go runtime writes to standard error for panics and crashes;
closing Stderr may cause those messages to go elsewhere, perhaps
to a file opened later.
var Stdout *File
Stdin, Stdout, and Stderr are open Files pointing to the standard input,
standard output, and standard error file descriptors.
Note that the Go runtime writes to standard error for panics and crashes;
closing Stderr may cause those messages to go elsewhere, perhaps
to a file opened later.
func Symlink(oldname, newname string) error
Symlink creates newname as a symbolic link to oldname.
If there is an error, it will be of type *LinkError.
func TempDir() string
TempDir returns the default directory to use for temporary files.
On Unix systems, it returns $TMPDIR if non-empty, else /tmp.
On Windows, it uses GetTempPath, returning the first non-empty
value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory.
On Plan 9, it returns /tmp.
The directory is neither guaranteed to exist nor have accessible
permissions.
func Truncate(name string, size int64) error
Truncate changes the size of the named file.
If the file is a symbolic link, it changes the size of the link's target.
If there is an error, it will be of type *PathError.
func Unsetenv(key string) error
Unsetenv unsets a single environment variable.
func UserCacheDir() (string, error)
UserCacheDir returns the default root directory to use for user-specific
cached data. Users should create their own application-specific subdirectory
within this one and use that.
On Unix systems, it returns $XDG_CACHE_HOME as specified by
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if
non-empty, else $HOME/.cache.
On Darwin, it returns $HOME/Library/Caches.
On Windows, it returns %LocalAppData%.
On Plan 9, it returns $home/lib/cache.
If the location cannot be determined (for example, $HOME is not defined),
then it will return an error.
func UserConfigDir() (string, error)
UserConfigDir returns the default root directory to use for user-specific
configuration data. Users should create their own application-specific
subdirectory within this one and use that.
On Unix systems, it returns $XDG_CONFIG_HOME as specified by
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if
non-empty, else $HOME/.config.
On Darwin, it returns $HOME/Library/Application Support.
On Windows, it returns %AppData%.
On Plan 9, it returns $home/lib.
If the location cannot be determined (for example, $HOME is not defined),
then it will return an error.
func UserHomeDir() (string, error)
UserHomeDir returns the current user's home directory.
On Unix, including macOS, it returns the $HOME environment variable.
On Windows, it returns %USERPROFILE%.
On Plan 9, it returns the $home environment variable.
The pages are generated with Goldsv0.1.6. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project and developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.