diff --git a/day01/devcontainer/.devcontainer/devcontainer.json b/day01/devcontainer/.devcontainer/devcontainer.json new file mode 100644 index 0000000..5355bf6 --- /dev/null +++ b/day01/devcontainer/.devcontainer/devcontainer.json @@ -0,0 +1,29 @@ +{ + "name": "Go Dev Container (demo)", + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "ghcr.io/devcontainers/features/common-utils:2": {}, + "ghcr.io/devcontainers/features/go:1": { + "version": "1.25" + } + }, + "remoteUser": "vscode", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "postCreateCommand": "cd demo && go mod download && go install github.com/go-delve/delve/cmd/dlv@latest", + "customizations": { + "vscode": { + "extensions": ["golang.go"], + "settings": { + "go.useLanguageServer": true, + "go.toolsManagement.autoUpdate": true, + "go.gopath": "/go", + "go.testFlags": ["-v"], + "go.lintTool": "golangci-lint", + "go.lintFlags": ["--fast"], + "[go]": { + "editor.formatOnSave": true + } + } + } + } +} diff --git a/day01/devcontainer/.vscode/launch.json b/day01/devcontainer/.vscode/launch.json new file mode 100644 index 0000000..aeb72c6 --- /dev/null +++ b/day01/devcontainer/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "$schema": "https://json.schemastore.org/launch.json", + "version": "0.2.0", + "configurations": [ + { + "name": "Debug demo/main.go", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}/demo", + "cwd": "${workspaceFolder}/demo", + "console": "integratedTerminal" + }, + { + "name": "Debug demo tests", + "type": "go", + "request": "launch", + "mode": "test", + "program": "${workspaceFolder}/demo", + "cwd": "${workspaceFolder}/demo", + "console": "integratedTerminal" + } + ] +} diff --git a/day01/devcontainer/README.md b/day01/devcontainer/README.md new file mode 100644 index 0000000..7db051b --- /dev/null +++ b/day01/devcontainer/README.md @@ -0,0 +1,31 @@ +## 使用 Dev Container 开发 demo 工程 + +此目录下的 `demo/` 是一个 Go 工程。已提供 VS Code Dev Container 配置,支持在容器内进行开发与调试。 + +### 快速开始 +- 前置:本地安装 VS Code 与 Dev Containers 扩展(Microsoft 提供)。 +- 打开文件夹:在 VS Code 中打开 `day01/devcontainer` 目录。 +- 重新在容器中打开:命令面板运行 “Dev Containers: Reopen in Container”。 +- 首次启动会执行依赖下载:`postCreateCommand` 会在 `demo/` 下执行 `go mod download`。 +- 镜像说明:使用 `mcr.microsoft.com/devcontainers/base:ubuntu`,通过 Dev Containers Feature 安装 Go(版本 1.25)。 + +### 容器内开发 +- 代码位置:`/workspaces/<当前打开的文件夹>/demo`。 +- 常用操作: + - 运行:在容器终端进入 `demo/` 目录后执行 `go run main.go` + - 构建:`go build` + - 测试:`go test ./...` +- 已安装:Go 工具链与 VS Code Go 扩展;保存时自动格式化与常用 lint 设置。 + +### 调试 +- 已自动安装 Delve(`dlv`)。 +- VS Code 已提供调试配置:[day01/devcontainer/.vscode/launch.json](day01/devcontainer/.vscode/launch.json) + - 直接在 “Run and Debug” 视图选择 “Debug demo/main.go” 或 “Debug demo tests”。 + - 断点与变量查看可在容器内正常使用。 + +### 备注 +- 如需额外工具(如 `golangci-lint` 的安装或 `dlv` 调试器),可在 `.devcontainer/devcontainer.json` 中增加特性或 `postCreateCommand`。 + +# devcontainer demo 工程 + +针对简单场景: 直接用 git bash 做完 vscode的命令工具 来使用 \ No newline at end of file diff --git a/day01/devcontainer/demo/go.mod b/day01/devcontainer/demo/go.mod new file mode 100644 index 0000000..41e99c4 --- /dev/null +++ b/day01/devcontainer/demo/go.mod @@ -0,0 +1,3 @@ +module demo + +go 1.25.5 diff --git a/day01/devcontainer/demo/main.go b/day01/devcontainer/demo/main.go new file mode 100644 index 0000000..16e2b22 --- /dev/null +++ b/day01/devcontainer/demo/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + println("Hello, World!") +}