简体   繁体   中英

How to write a file in specific data volume

I am trying to write in newly generated file in a specific attached volume to my container (a directory)

however i am not sure about the correct the syntax. Below my code:

// Write the certificates to disk
    f, _ := os.Create(filepath.Join("/data/certs/", "chamscertificate.pem"))
    f.Write(cert)
    f.Close()

    f, _ = os.Create("key.pem")
    f.Write(key)
    f.Close()
}

when executing "go run .", i get the "key.pem" but not the "certificate.pem".

You don't check for errors. If the file wasn't created, the information about why the file wasn't created will be in the error return value from os.Create .

f, err := os.Create(filepath.Join("/data/certs/", "chamscertificate.pem"))
if err != nil {
   log.Fatal(err)
}
... etc.

Note that f.Write and f.Close also return errors that should be checked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM