dtny30176
2016-05-09 20:32
浏览 262
已采纳

go不能在模板Execute的参数中将输出(字符串类型)用作io.Writer类型

It's easy to execute template ('tmplhtml' in my case) in 'go' to os.Stdout but how to write it to a string 'output' so I can later i.e. send html in mail using "gopkg.in/gomail.v2" ?

var output string
    t := template.Must(template.New("html table").Parse(tmplhtml))
    err = t.Execute(output, Files)
m.SetBody("text/html", output) //"gopkg.in/gomail.v2"

Build error reads 'cannot use output (type string) as type io.Writer in argument to t.Execute: string does not implement io.Writer (missing Write method)' I can implement Writer method but it is supposed to return integer Write(p []byte) (n int, err error)

图片转代码服务由CSDN问答提供 功能建议

很容易在“ <go>”操作系统中执行模板(在我的情况下为“ tmplhtml”)。 </ em>,但是如何将其写入字符串“输出”,以便以后可以使用“ gopkg.in/gomail.v2” </ code>在邮件中发送html?</ p>

  var输出字符串
t:= template.Must(template.New(“ html table”)。Parse(tmplhtml))
 err = t.Execute(输出,文件)
m.SetBody(“  text / html“,输出)//” gopkg.in/gomail.v2"
 </ pre> 
 
 

生成错误读取'不能将输出(类型字符串)用作 在t.Execute的参数中键入io.Writer。字符串不实现io.Writer(缺少Write方法)'</ strong>我可以实现Writer方法,但应该返回整数 Write(p [] byte) (n int,错误)</ strong> </ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题