我有以下控制器,它使用 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-certs
instead of scratch
。它包括 CA 證書,您的程序應該自動使用它們。
- 1 回答
- 0 關注
- 145 瀏覽
添加回答
舉報
0/150
提交
取消