Standard library / os
os.O_CREATE
Creates the file if missing; combine with an access mode and supply permissions. Example uses a disposable temporary workspace. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
const O_CREATE int = syscall.O_CREATWorking Example
Example Snippetgo
package main
import ( "fmt" "os")
func check(e error) { if e != nil { panic(e) }}func workspace() func() { root, e := os.MkdirTemp("", "bytemind-go-") check(e) old, e := os.Getwd() check(e) check(os.Chdir(root)) return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() { defer workspace()() f, e := os.OpenFile("new", os.O_WRONLY|os.O_CREATE, 0600) check(e) check(f.Close()) _, e = os.Stat("new") fmt.Println(e == nil)}