echo "package foo; type T struct {Var1 type1 `json:"var,omitempty"` // somecomment1}" | gofmt
-bash: json:var,omitempty: command not found
package foo
type T struct {
Var1 type1 // somecomment1
}
Hello,What is the best way to gofmt a program which is read from stdin. I am not too familiar with piping, but this almost workecho "package foo; type T struct {Var1 type1 `json:"var,omitempty"` // somecomment1}" | gofmt
this outputs-bash: json:var,omitempty: command not found
package foo
type T struct {
Var1 type1 // somecomment1
}
how can I make it to use field tag? or is there a better way than echoing the string.For the context, I am calling this through node.jsfunction format(src) {var cmd = 'echo "' + src + '" | gofmt'child_process.exec(cmd, function (err, stdout, stderr) {....});}where src is the program.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
hope echoing like this is still the best way to read from stdin.
var exec = require('child_process').exec;
var src = 'package main\nimport "fmt"\nfunc main() {\nfmt.Println("hello, world")\n}';
var gofmt = exec('gofmt', function (err, stdout, stderr) {
console.log(stdout);
});
gofmt.stdin.setEncoding = 'utf-8';
gofmt.stdin.write(src);
gofmt.stdin.end();