Go 远程调试

哪些场景可以用到远程调试?

  • Apple M1 M2 M3 不支持go 1.14 之前的版本
  • Golang 部分依赖不支持 window

这两个场景推荐使用 Docker。

Debugging a Go application inside a Docker container | The GoLand Blog
Updated and validated on November 17, 2022. You can find more tutorials on how to use containers here. You may also refer to the Docker and Kubernetes sections of our Help documentation. Go develop

以下是一个 Dockerfile 示例:


# 使用 1.14.15 镜像
FROM golang:1.14.15 as builder

# 下载 delve-1.6.1 源码到 当前项目,记得加到项目的 .gitignore
ADD delve-1.6.1 /go/delve
WORKDIR /go/delve/delve-1.6.1
# 开启代理编译安装 dlv
RUN https_proxy=http://192.168.31.2:1087 http_proxy=http://192.168.31.2:1087 \
 go install github.com/go-delve/delve/cmd/dlv

# 拷贝代码
COPY . /build
WORKDIR /build/web
# 开始编译
RUN https_proxy=http://192.168.31.2:1087 http_proxy=http://192.168.31.2:1087 \
	GO111MODULE=on GOPROXY="https://goproxy.cn,direct" \
	GOPRIVATE="codeup.aliyun.com" \
  go build -o bin/web \
    # 必须加上下面一行编译参数
		-gcflags "all=-N -l" \
    -tags=jsoniter,prototype main.go


FROM debian:buster

EXPOSE 8080 40001

WORKDIR /
COPY --from=builder /build/web /web
RUN ls /
COPY --from=builder /go/bin/dlv /web/
RUN ls /web
COPY --from=builder /build/web/bin/web /web/bin/web

WORKDIR /web

#ENTRYPOINT [ "/bookadv-cmd" ]
CMD ["/web/dlv", \
"--listen=:40001", "--headless=true", "--api-version=2", "--accept-multiclient", \
## 需要注意,如果使用项目自身的参数,需要加上 "--",否则会认为是 dlv 的参数进而发生错误。
"exec", "/web/bin/web", "--", "--server_address=:8080", "http"]

Read more

Git hook 开发和实践,提升自动化效率

Git hook 开发和实践,提升自动化效率

我们使用 git 进行版本控制,期间会触发很多事件,这些利用好这些事件做好自动化,能帮我提升效率。git hook 就是一个这样的工具,在特定的事件中执行特定的钩子。 ╰─➤ ls .git/hooks applypatch-msg.sample post-update.sample pre-merge-commit.sample pre-receive.sample update.sample commit-msg.sample pre-applypatch.sample pre-push.sample prepare-commit-msg.sample fsmonitor-watchman.sample pre-commit.sample pre-rebase.sample push-to-checkout.sample 设置钩子路径 git 仓库的钩子存放路径由 core.hooksPath 控制,默认是在项目的 .git/hooks。它不能使用版本控制

By brian

MacOS 安装了最新版 Docker,命令行找不到了?

它藏在 /Applications/Docker.app 中,可以使用 find 命令查看: $cd /Applications/Docker.app $find . -name "docker" ./Contents/Resources/bin/docker 将 bin 目录拼接到 PATH 环境变量即可,一般可以追加到 ~/.bashrc ~/.zshrc 中。 export PATH=/Applications/Docker.app/Contents/Resources/bin:$PATH source ~/.zshrc 使环境变量生效,执行 docker 检查版本 $ source ~/.zshrc $ docker --version Docker

By brian
飞书集成平台 x Grafana:打造监控告警系统全攻略

飞书集成平台 x Grafana:打造监控告警系统全攻略

Grafana告警内容设置 告警内容分为:告警标题、告警说明、告警详情。告警标题和告警说明用来描述告警的规则。告警详情,描述告警的规则和具体的值。 告警详情 Description 设置 1. 打印所有的标签 {{ $labels }} alertname=High CPU usage, grafana_folder=CPU alerts, instance=server1 2. 自定义格式化打印所有的标签 {{ range $k, $v := $labels -}} {{ $k }}={{ $v }} {{ end }} alertname=High CPU usage grafana_folder=CPU alerts instance=server1 3. 打印单个标签 The host {{ index $labels

By brian
沪ICP备2022013452号-1