如何在Go中打印http响应正文?
我正在使用Google Cloud Run运行应用程序,例如,我在Go中有以下脚本: 包干管 进口 fmt 日志 net/http 操作系统 操作系统/执行器 func handlerw http.ResponseWriter,r*http.Request{ Printhelloworld:收到一个请求 cmd:=exec.CommandContextr.Context,/bin/sh,script.sh cmd.Stderr=os.Stderr 输出,错误:=cmd.Output 如果错误!=零{ w、 写头500 } w、 注销 } func main{ 正在启动服务器。。。 http.HandleFunc/,handler 端口:=os.GetenvPORT 如果端口=={ 端口=8080 } log.Printfhelloworld:侦听%s,端口 log.Fatalhttp.ListenAndServefmt.Sprintf:%s,端口,无 } 我需要从script.sh命令中记录.print响应。我怎么做?在您的服务器中 w、 注销 以[]字节的形式从script.sh发送响应。您可以在该行上方添加以下内容如何在Go中打印http响应正文?,go,Go,我正在使用Google Cloud Run运行应用程序,例如,我在Go中有以下脚本: 包干管 进口 fmt 日志 net/http 操作系统 操作系统/执行器 func handlerw http.ResponseWriter,r*http.Request{ Printhelloworld:收到一个请求 cmd:=exec.CommandContextr.Context,/bin/sh,script.sh cmd.Stderr=os.Stderr 输出,错误:=cmd.Output 如果错误!=
log.Printstringout您的问题似乎可以自行回答,您可以通过调用log.Print来log.Print,您已经在代码的其他地方使用了log.Print,因此不清楚您遇到了什么问题。你能澄清你的问题吗?与云跑无关,这是纯粹的围棋问题。你在网上有很多这方面的教程/例子。但是,为什么要在Go代码中调用SH脚本?为什么不把所有的代码都写进去呢?