<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Technical on Billy's Blog</title><link>https://virgoc0der.github.io/categories/technical/</link><description>Recent content in Technical on Billy's Blog</description><generator>Hugo</generator><language>zh-CN</language><managingEditor>billychen826@gmail.com (Billy)</managingEditor><webMaster>billychen826@gmail.com (Billy)</webMaster><lastBuildDate>Mon, 31 Mar 2025 10:30:00 +0800</lastBuildDate><atom:link href="https://virgoc0der.github.io/categories/technical/index.xml" rel="self" type="application/rss+xml"/><item><title>Go语言入门指南：从零开始的Go编程之旅</title><link>https://virgoc0der.github.io/posts/golang-beginner-guide/</link><pubDate>Mon, 31 Mar 2025 10:30:00 +0800</pubDate><author>billychen826@gmail.com (Billy)</author><guid>https://virgoc0der.github.io/posts/golang-beginner-guide/</guid><description>&lt;h1 id="go语言入门指南从零开始的go编程之旅">Go语言入门指南：从零开始的Go编程之旅&lt;/h1>
&lt;p>Go语言（也称为Golang）是由Google开发的一种静态类型、编译型编程语言，以其简洁的语法、高效的并发处理和强大的标准库而闻名。自2009年发布以来，Go已成为云原生应用、微服务和高性能后端系统的首选语言之一。本文将带领初学者踏上Go语言学习之旅，从环境搭建到基础语法，再到实用示例，全面介绍Go编程的基础知识。&lt;/p>
&lt;h2 id="为什么选择go语言">为什么选择Go语言？&lt;/h2>
&lt;p>在开始学习Go之前，让我们了解为什么Go语言值得学习：&lt;/p>
&lt;ol>
&lt;li>&lt;strong>简洁易学&lt;/strong>：Go的语法简洁明了，学习曲线相对平缓，尤其适合已有其他编程语言经验的开发者&lt;/li>
&lt;li>&lt;strong>并发支持&lt;/strong>：内置的goroutine和channel使并发编程变得简单而强大&lt;/li>
&lt;li>&lt;strong>优秀的性能&lt;/strong>：接近C/C++的性能，但具有更高的开发效率&lt;/li>
&lt;li>&lt;strong>强大的标准库&lt;/strong>：丰富的标准库可以满足大多数常见需求，减少对第三方依赖的需求&lt;/li>
&lt;li>&lt;strong>跨平台支持&lt;/strong>：支持Windows、macOS、Linux等多种操作系统&lt;/li>
&lt;li>&lt;strong>就业机会&lt;/strong>：Go在云计算、微服务、DevOps等热门领域应用广泛，就业前景良好&lt;/li>
&lt;/ol>
&lt;h2 id="环境搭建">环境搭建&lt;/h2>
&lt;h3 id="1-安装go">1. 安装Go&lt;/h3>
&lt;p>首先，我们需要在系统上安装Go。访问&lt;a href="https://golang.org/dl/">Go官方下载页面&lt;/a>获取适合您系统的安装包。&lt;/p>
&lt;p>&lt;strong>macOS安装&lt;/strong>:&lt;/p>
&lt;p>使用Homebrew安装：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>brew install go
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>或使用官方安装包安装。&lt;/p>
&lt;p>&lt;strong>Linux安装&lt;/strong>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#414868;font-style:italic"># Ubuntu/Debian&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo apt-get update
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo apt-get install golang
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#414868;font-style:italic"># CentOS/RHEL&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo yum install golang
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>Windows安装&lt;/strong>:&lt;/p>
&lt;p>下载并运行MSI安装程序，按照向导完成安装。&lt;/p>
&lt;h3 id="2-验证安装">2. 验证安装&lt;/h3>
&lt;p>安装完成后，打开终端/命令提示符，运行以下命令验证安装：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>go version
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>您应该看到类似以下的输出：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>go version go1.22.1 darwin/amd64
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="3-配置工作区">3. 配置工作区&lt;/h3>
&lt;p>Go 1.13及更高版本支持模块化开发，使得工作目录配置变得更加简单。但了解一下基本的GOPATH结构依然有所裨益：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>GOPATH/
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── bin/ # 编译后的可执行文件
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── pkg/ # 编译后的包文件
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>└── src/ # 源代码
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>现代Go项目通常使用Go Modules来管理依赖：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#414868;font-style:italic"># 创建新项目目录&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mkdir -p ~/projects/my-go-app
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#9ece6a">cd&lt;/span> ~/projects/my-go-app
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#414868;font-style:italic"># 初始化Go模块&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>go mod init github.com/yourusername/my-go-app
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="go语言基础">Go语言基础&lt;/h2>
&lt;h3 id="1-第一个go程序">1. 第一个Go程序&lt;/h3>
&lt;p>让我们从经典的&amp;quot;Hello, World!&amp;ldquo;程序开始：&lt;/p></description></item><item><title>使用Docker构建高效的Golang开发环境：完整指南</title><link>https://virgoc0der.github.io/posts/golang-docker/</link><pubDate>Thu, 27 Mar 2025 11:32:53 +0800</pubDate><author>billychen826@gmail.com (Billy)</author><guid>https://virgoc0der.github.io/posts/golang-docker/</guid><description>&lt;h1 id="使用docker构建高效的golang开发环境完整指南">使用Docker构建高效的Golang开发环境：完整指南&lt;/h1>
&lt;p>在现代软件开发中，保持开发环境的一致性和可复制性至关重要。无论是团队协作还是个人项目，环境差异常常导致&amp;quot;在我的机器上能运行&amp;quot;的问题。Docker作为容器化技术的代表，为解决这一问题提供了优雅的解决方案。本文将详细介绍如何使用Docker构建一个高效的Golang开发环境，包括多阶段构建、热重载和最佳实践。&lt;/p>
&lt;h2 id="为什么选择docker--golang">为什么选择Docker + Golang？&lt;/h2>
&lt;p>Golang和Docker的组合有着天然的契合性：&lt;/p>
&lt;ol>
&lt;li>&lt;strong>轻量级&lt;/strong>：Go编译后的二进制文件体积小，启动快，非常适合容器化部署&lt;/li>
&lt;li>&lt;strong>跨平台&lt;/strong>：通过Docker容器，可以在任何支持Docker的平台上获得一致的开发体验&lt;/li>
&lt;li>&lt;strong>依赖管理&lt;/strong>：容器化环境避免了&amp;quot;依赖地狱&amp;quot;问题，确保所有开发者使用相同的依赖版本&lt;/li>
&lt;li>&lt;strong>隔离性&lt;/strong>：开发环境与主机系统隔离，避免污染本地环境&lt;/li>
&lt;li>&lt;strong>CI/CD友好&lt;/strong>：容器化的开发环境可以无缝集成到CI/CD流程中&lt;/li>
&lt;/ol>
&lt;h2 id="环境准备">环境准备&lt;/h2>
&lt;p>在开始之前，请确保您的系统已安装以下软件：&lt;/p>
&lt;ul>
&lt;li>Docker（&lt;a href="https://docs.docker.com/get-docker/">安装指南&lt;/a>）&lt;/li>
&lt;li>Docker Compose（&lt;a href="https://docs.docker.com/compose/install/">安装指南&lt;/a>）&lt;/li>
&lt;li>Git（&lt;a href="https://git-scm.com/downloads">安装指南&lt;/a>）&lt;/li>
&lt;/ul>
&lt;h2 id="项目结构">项目结构&lt;/h2>
&lt;p>我们将创建一个具有以下结构的项目：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>docker-golang-dev/
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── .air.toml # Air 热重载配置文件
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── Dockerfile # 多阶段构建的 Dockerfile
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── docker-compose.yml # Docker Compose 配置文件
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── go.mod # Go 模块定义
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>├── go.sum # Go 模块校验和
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>└── src/ # Go 源代码目录
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> └── main.go # 示例应用程序
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="步骤一创建基础项目结构">步骤一：创建基础项目结构&lt;/h2>
&lt;p>首先，让我们创建项目目录并初始化Go模块：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>mkdir -p docker-golang-dev/src
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#9ece6a">cd&lt;/span> docker-golang-dev
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>go mod init github.com/yourusername/docker-golang-dev
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>touch go.sum
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="步骤二编写dockerfile">步骤二：编写Dockerfile&lt;/h2>
&lt;p>Dockerfile是构建Docker镜像的核心配置文件。我们将使用多阶段构建来优化镜像大小和构建过程。&lt;/p></description></item><item><title>在Mac Mini上部署私有化大语言模型</title><link>https://virgoc0der.github.io/posts/first/</link><pubDate>Mon, 24 Mar 2025 15:56:48 +0800</pubDate><author>billychen826@gmail.com (Billy)</author><guid>https://virgoc0der.github.io/posts/first/</guid><description>&lt;h2 id="环境准备">环境准备&lt;/h2>
&lt;ol>
&lt;li>系统要求：
&lt;ul>
&lt;li>macOS Monterey 12.3 或更高版本&lt;/li>
&lt;li>至少16GB内存（推荐32GB）&lt;/li>
&lt;li>安装Homebrew包管理器&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#414868;font-style:italic"># 安装Homebrew&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>/bin/bash -c &lt;span style="color:#9ece6a">&amp;#34;&lt;/span>&lt;span style="color:#bb9af7">$(&lt;/span>curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh&lt;span style="color:#bb9af7">)&lt;/span>&lt;span style="color:#9ece6a">&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="安装部署">安装部署&lt;/h2>
&lt;h3 id="1-安装ollama">1. 安装Ollama&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#414868;font-style:italic"># 通过curl直接安装&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>curl -fsSL https://ollama.com/install.sh | sh
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#414868;font-style:italic"># 启动ollama服务&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ollama serve
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2-部署open-webui">2. 部署Open WebUI&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#414868;font-style:italic"># 使用Docker运行webui容器&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>docker run -d -p 3000:8080 &lt;span style="color:#7aa2f7">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#7aa2f7">&lt;/span> -v ollama:/root/.ollama &lt;span style="color:#7aa2f7">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#7aa2f7">&lt;/span> --name open-webui &lt;span style="color:#7aa2f7">\
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#7aa2f7">&lt;/span> ghcr.io/open-webui/open-webui:main
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="模型加载">模型加载&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#c0caf5;background-color:#1a1b26;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#414868;font-style:italic"># 下载llama3模型（根据需求替换模型名称）&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ollama pull llama3
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#414868;font-style:italic"># 查看已安装模型&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ollama list
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="访问验证">访问验证&lt;/h2>
&lt;ol>
&lt;li>
&lt;p>打开浏览器访问：&lt;/p>
&lt;ul>
&lt;li>Ollama管理界面：http://localhost:11434&lt;/li>
&lt;li>WebUI界面：http://localhost:3000&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>在WebUI界面选择模型即可开始对话&lt;/p>
&lt;/li>
&lt;/ol>
&lt;h2 id="注意事项">注意事项&lt;/h2>
&lt;ol>
&lt;li>确保3000/11434端口未被占用&lt;/li>
&lt;li>首次下载模型需要较长时间（取决于网络环境）&lt;/li>
&lt;li>建议配合Ngrok实现内网穿透&lt;/li>
&lt;li>使用GPU加速需要额外配置Metal后端&lt;/li>
&lt;/ol></description></item></channel></rss>