亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Go App 工作但在 Docker 中 - JSON 輸入的意外結束

Go App 工作但在 Docker 中 - JSON 輸入的意外結束

Go
SMILET 2023-03-29 17:20:31
我有以下控制器,它使用 Go 中內置的包裝器進行外部 API 調用。問題是,如果我在沒有 docker 的情況下運行我的服務器,端點將返回有效數據。但是,當我從 docker 中運行它時,我得到的錯誤是unexpected end of JSON input.回家去package controllersimport (  "fmt"  "encoding/json"  "net/http"  "time"  "strconv"  cmc "github.com/coincircle/go-coinmarketcap")type HomeController struct{}func NewHomeController() *HomeController {  return &HomeController{}}func (hc HomeController) IndexEndpoint(w http.ResponseWriter, r *http.Request) {  threeMonths := int64(60 * 60 * 24 * 90)  now := time.Now()  secs := now.Unix()  start := secs - threeMonths  end := secs  fmt.Println("Time is " + strconv.FormatInt(end, 10))  graph, _ := cmc.TickerGraph(&cmc.TickerGraphOptions{    Start: start,    End: end,    Symbol: "ETH",  })  fmt.Println(graph)  w.Header().Set("Access-Control-Allow-Origin", "*")  w.Header().Set("Content-Type", "application/json")  w.WriteHeader(http.StatusCreated)  json.NewEncoder(w).Encode(graph)}這是我的泊塢窗設置:文件FROM golang:latest AS builderCOPY . $GOPATH/src/github.com/gohuygo/cryptodemo-apiWORKDIR $GOPATH/src/github.com/gohuygo/cryptodemo-apiRUN go get ./RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /app .FROM scratchCOPY --from=builder /app ./ENTRYPOINT ["./app"]為什么在涉及 docker 時抱怨 json 錯誤(即如何解決這個問題)?謝謝
查看完整描述

1 回答

?
炎炎設計

TA貢獻1808條經驗 獲得超4個贊

您的 go 應用程序可能會嘗試建立傳出 HTTPS 連接,但scratch容器不包含驗證 TLS 證書所需的 CA 證書。

在這種情況下考慮使用centurylink/ca-certsinstead of scratch。它包括 CA 證書,您的程序應該自動使用它們。


查看完整回答
反對 回復 2023-03-29
  • 1 回答
  • 0 關注
  • 145 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號