What do you mean by “doesn’t work?” One thing I notice here is that you don’t seem to have any line breaks in the actual string. Maybe try the backticks instead, e.g.:
ioutil.WriteFile("main.go", `package main
import "format"
//...
`)
I mean that it gives error, with your code it says
too few arguments in call to ioutil.WriteFilecompilerWrongArgCount
cannot use package main import "format" //... (untyped string constant “package main\n\t\t\t\timport “format”\n\t\t\t\t//…\n\t\t\t\t”) as []byte value in argument to ioutil.WriteFilecompilerIncompatibleAssign
I didn’t give a complete example. My point was that when you have "package main" + "import 'fmt'" + ..., you end up with a string of text all on one line. Instead of using separate strings and appending them together, just use backticks (`) around the string and then you don’t need to append the strings together.