golang的踩坑

codeless發表於2018-08-14

title: golang 踩坑 date: 2018-08-14 20:10:55 tags:

- go

> x509 error when using HTTPS inside a Docker container

因為 docker 中沒有 CA 證書。

普通的映象解決辦法

FROM ubuntu:14.04.1

RUN apt-get update
RUN apt-get install -y ca-certificates

CMD curl https://www.google.com

如果是 alpine 的參考這個:

FROM docker.finogeeks.club/base/alpine
MAINTAINER "zhuzhenfeng@finogeeks.club"

RUN set -ex \
    && apk add --no-cache ca-certificates

COPY src/wallet/wallet /opt/wallet

ENTRYPOINT /opt/wallet

> panic: runtime error: invalid memory address or nil pointer dereference > [signal 0xb code=0x1 addr=0x38 pc=0x26df]

"An error is returned if caused by client policy (such as CheckRedirect), or if there was an HTTP protocol error. A non-2xx response doesn't cause an error.

When err is nil, resp always contains a non-nil resp.Body."

是 http 請求的時候,defer res.Body.Close() 引起的,應該在 err 檢查之後。

The defer only defers the function call. The field and method are accessed immediately.

更多原創文章乾貨分享,請關注公眾號
  • golang的踩坑
  • 加微信實戰群請加微信(註明:實戰群):gocnio