dongmacheng3222
2018-05-01 02:27
浏览 14
已采纳

Go服务器在arm64上返回损坏的图像

I've written a simple HTTP image server:

go/src/demo/demo.go:

package main

import (
  "net/http"
  "github.com/gorilla/mux"
)

func main() {
  router := mux.NewRouter()
  router.HandleFunc("/foobar", func(w http.ResponseWriter, r *http.Request) {
    http.ServeFile(w, r, "/home/foobar/test.jpg")
  })

  http.ListenAndServe(":5000", router)
}

I compile it (PWD=$HOME/go/src/demo):

GOPATH=$PWD/../../ go build -o demo

And run:

./demo

Then in Chrome I open the URL. The image is corrupt -- reloading produces different corruption each time, once in a while it is fine. Larger images (~200KB) fail more often, smaller images (~20KB) fail less often.

Additional details:

go version produces go version go1.9.5 linux/arm64.

On my Macbook, this causes no issues -- only occurs on arm64 (looks like ResponseWriter does not implement flushing). I'm at a loss. Any ideas?

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

我编写了一个简单的HTTP图像服务器:

go / src /demo/demo.go:

 包main 
 
import(
“ net / http” 
“ github.com/gorilla/mux” 
)\  n 
func main(){
 router:= mux.NewRouter()
 router.HandleFunc(“ / foobar”,func(w http.ResponseWriter,r * http.Request){
 http.ServeFile(w,  r,“ /home/foobar/test.jpg")
})
 
 http.ListenAndServe(”:5000“,路由器)
} 
   
 
 <  p>我编译它(PWD = $ HOME / go / src / demo): 
 
 
  GOPATH = $ PWD /../../ go build -o demo 
    
 
 

并运行:

  ./ demo 
   
 
 <  p>然后在Chrome中打开URL。 映像已损坏-每次重新加载都会产生不同的损坏,有时会很好。 较大的图像(〜200KB)失败的频率更高,较小的图像(〜20KB)失败的频率更低。 
 
 

其他详细信息:

go版本 产生 go版本go1.9.5 linux / arm64

在我的Macbook上,这不会引起问题-仅发生在arm64上(看起来像ResponseWriter 不执行冲洗)。 我很茫然。 有什么想法吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongpian4954 2018-05-01 03:38
    已采纳

    Looks like it was an issue with the go1.9.5 release. Updated toolchain to go1.10.1 and the issue disappeared.

    点赞 评论

相关推荐 更多相似问题