PicoClaw - Go 单文件部署王
约 905 字大约 3 分钟
2026-03-07
Go 单文件部署王,编译为静态链接的单文件二进制,天然适合 Serverless 部署。
核心特性
单文件部署
- 编译为静态链接的单文件二进制
- 无外部依赖,开箱即用
- 跨平台支持(Linux/Mac/Windows)
- 文件大小 < 20MB
无状态设计
- Stateless 架构,天然适合 Serverless
- 支持水平扩展
- 快速启动(< 100ms)
- 零配置运行
轻量高效
- 使用 Goroutine 处理并发
- 内存占用低(< 30MB)
- CPU 利用率优化
- 支持高并发请求
云原生友好
- AWS Lambda 原生支持
- 阿里云函数计算兼容
- Google Cloud Functions 适配
- 容器化部署简单
快速开始
下载安装
从 GitHub Releases 下载对应平台的二进制文件:
# Linux
wget https://github.com/sipeed/picoclaw/releases/latest/download/picoclaw-linux-amd64
chmod +x picoclaw-linux-amd64
./picoclaw-linux-amd64
# macOS
wget https://github.com/sipeed/picoclaw/releases/latest/download/picoclaw-darwin-amd64
chmod +x picoclaw-darwin-amd64
./picoclaw-darwin-amd64
# Windows
# 下载 picoclaw-windows-amd64.exe 直接运行从源码构建
# 克隆仓库
git clone https://github.com/sipeed/picoclaw.git
cd picoclaw
# 构建
go build -ldflags="-s -w" -o picoclaw
# 运行
./picoclaw配置
创建 config.yaml 文件:
server:
port: 8080
host: 0.0.0.0
llm:
provider: anthropic
api_key: ${ANTHROPIC_API_KEY}
model: claude-3-5-sonnet-20241022
memory:
type: redis # 或 memory(内存模式)
redis_url: redis://localhost:6379技术架构
核心技术栈
- 语言: Go 1.21+
- 并发模型: Goroutine + Channel
- HTTP 框架: 标准库 net/http
- 序列化: encoding/json
架构特点
- 单进程多协程
- 事件驱动架构
- 模块化设计
- 插件系统
性能指标
- 启动时间: < 100ms
- 内存占用: < 30MB
- 并发处理: 10000+ req/s
- 响应延迟: < 10ms (P99)
Serverless 部署
AWS Lambda
创建 lambda.go:
package main
import (
"github.com/aws/aws-lambda-go/lambda"
"github.com/sipeed/picoclaw/core"
)
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
agent := core.NewAgent()
result := agent.Process(request.Body)
return events.APIGatewayProxyResponse{
StatusCode: 200,
Body: result,
}, nil
}
func main() {
lambda.Start(handler)
}部署:
GOOS=linux GOARCH=amd64 go build -o bootstrap lambda.go
zip function.zip bootstrap
aws lambda create-function --function-name picoclaw \
--runtime provided.al2 \
--handler bootstrap \
--zip-file fileb://function.zip阿里云函数计算
# 使用 Funcraft 部署
fun deploy -t template.ymlDocker 部署
FROM golang:1.21-alpine AS builder
WORKDIR /app
COPY . .
RUN go build -ldflags="-s -w" -o picoclaw
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/picoclaw .
EXPOSE 8080
CMD ["./picoclaw"]构建和运行:
docker build -t picoclaw .
docker run -p 8080:8080 picoclaw高级功能
插件系统
package main
import "github.com/sipeed/picoclaw/plugin"
func init() {
plugin.Register("custom-tool", &CustomTool{})
}
type CustomTool struct{}
func (t *CustomTool) Execute(input string) (string, error) {
// 自定义逻辑
return "result", nil
}中间件支持
func LoggingMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("Request: %s %s", r.Method, r.URL.Path)
next.ServeHTTP(w, r)
})
}健康检查
# 健康检查端点
curl http://localhost:8080/health
# 响应
{
"status": "healthy",
"uptime": "2h30m",
"memory": "25MB"
}性能对比
| 指标 | PicoClaw | Node.js 版 | Python 版 |
|---|---|---|---|
| 启动时间 | 100ms | 800ms | 1200ms |
| 内存占用 | 30MB | 150MB | 200MB |
| 并发处理 | 10000/s | 2000/s | 500/s |
| 文件大小 | 18MB | 80MB | 120MB |
适用场景
推荐使用
- Serverless 部署(AWS Lambda、阿里云函数计算)
- 企业内网快速搭建内部助手
- 资源受限环境
- 需要快速部署的场景
- 微服务架构
不推荐使用
- 需要复杂状态管理的场景
- 需要 Node.js 生态的场景
- 需要动态加载代码的场景
相关链接
- GitHub: sipeed/picoclaw
- 文档: 使用文档
- 问题反馈: Issues
- 更新日志: Changelog
贡献
欢迎贡献代码、报告问题或提出建议!
# 克隆仓库
git clone https://github.com/sipeed/picoclaw.git
# 安装依赖
cd picoclaw
go mod download
# 运行测试
go test ./...
# 构建
go build -o picoclaw许可证
MIT License - 详见 LICENSE