SHARE
TWEET

Untitled

a guest Oct 21st, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Snippet: OpenFile with more options. Last param is the permission mode
  2.     // Second param is the attributes when opening
  3.     // Use these attributes individually or combined
  4.     // with an OR for second arg of OpenFile()
  5.     // e.g. os.O_CREATE|os.O_APPEND
  6.     // or os.O_CREATE|os.O_TRUNC|os.O_WRONLY
  7.     // os.O_RDONLY // Read only
  8.     // os.O_WRONLY // Write only
  9.     // os.O_RDWR // Read and write
  10.     // os.O_APPEND // Append to end of file
  11.     // os.O_CREATE // Create is none exist
  12.     // os.O_TRUNC // Truncate file when opening
  13.  
  14.     file, err := os.OpenFile("test.txt", os.O_APPEND, 0666)
  15.     if err != nil {
  16.         log.Fatal(err)
  17.     }
  18.     defer func() { _ = file.Close() }()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top