Just a few weeks until the 2021 JavaScript Full-Stack Bootcamp opens.
Signup to the waiting list!


This one-liner assigns a string to a slice of bytes:

package main

func main() {

    var s string

    //...

    b := []byte(s)

    //...
}

I found this useful when using ioutil.WriteFile, which accepts a bytes slice as its data parameter:

WriteFile func(filename string, data []byte, perm os.FileMode) error

e.g.:

ioutil.WriteFile(filePath, []byte(content), 0755)


The 2021 JavaScript Full-Stack Bootcamp will start at the end of March 2021. Don't miss this opportunity, signup to the waiting list!

More go tutorials: