os.WriteFile

The Go function that writes a slice of bytes to a file in one call, creating it with the permission mode you give if it does not exist.

In more detail

The mode, such as 0o600, applies only when the file is created, and the process umask can remove bits from it. It replaces any existing contents. Choose a restrictive mode for anything sensitive.

Example

err := os.WriteFile("probe.conf", conf, 0o600)

Related terms

Taught in

References