encore-go-getting-started by encoredev/skills
npx skills add https://github.com/encoredev/skills --skill encore-go-getting-started# macOS
brew install encoredev/tap/encore
# Linux/WSL
curl -L https://encore.dev/install.sh | bash
# Windows (PowerShell)
iwr https://encore.dev/install.ps1 | iex
# 交互式 - 从模板中选择
encore app create my-app
# 或者从一个空白的 Go 应用开始
encore app create my-app --example=hello-world
一个最小的 Encore Go 应用:
my-app/
├── encore.app # 应用配置
├── go.mod # Go 模块
└── hello/ # 一个服务(包含 API 的包)
└── hello.go # API 端点
// encore.app
{
"id": "my-app"
}
此文件标记了你的 Encore 应用的根目录。id 是你的应用的唯一标识符。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
在 Encore Go 中,任何包含 //encore:api 端点的包都会成为一个服务:
// hello/hello.go
package hello
import "context"
type Response struct {
Message string `json:"message"`
}
//encore:api public method=GET path=/hello
func Hello(ctx context.Context) (*Response, error) {
return &Response{Message: "Hello, World!"}, nil
}
# 启动开发服务器
encore run
# 你的 API 现在可以通过 http://localhost:4000 访问
# 打开本地开发仪表板
encore run
# 然后访问 http://localhost:9400
仪表板显示:
| 命令 | 描述 |
|---|---|
encore run | 启动本地开发服务器 |
encore test | 运行测试(底层使用 go test) |
encore db shell <db> | 打开数据库的 psql 命令行界面 |
encore gen client | 生成 API 客户端代码 |
encore app link | 链接到现有的 Encore Cloud 应用 |
type GetUserParams struct {
ID string
}
type User struct {
ID string `json:"id"`
Name string `json:"name"`
}
//encore:api public method=GET path=/users/:id
func GetUser(ctx context.Context, params *GetUserParams) (*User, error) {
return &User{ID: params.ID, Name: "John"}, nil
}
// db.go
package hello
import "encore.dev/storage/sqldb"
var db = sqldb.NewDatabase("mydb", sqldb.DatabaseConfig{
Migrations: "./migrations",
})
创建迁移文件:
-- hello/migrations/1_create_table.up.sql
CREATE TABLE items (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL
);
import "encore.dev/storage/sqldb"
type Item struct {
ID int
Name string
}
func getItem(ctx context.Context, id int) (*Item, error) {
item, err := sqldb.QueryRow[Item](ctx, db, `
SELECT id, name FROM items WHERE id = $1
`, id)
if err != nil {
return nil, err
}
return item, nil
}
encore-go-api 技能)encore-go-auth 技能)encore-go-infrastructure 技能)encore app link 然后 git push encore每周安装量
119
代码仓库
GitHub 星标数
20
首次出现
2026年1月21日
安全审计
安装于
opencode100
gemini-cli99
codex99
claude-code92
github-copilot81
cursor78
# macOS
brew install encoredev/tap/encore
# Linux/WSL
curl -L https://encore.dev/install.sh | bash
# Windows (PowerShell)
iwr https://encore.dev/install.ps1 | iex
# Interactive - choose from templates
encore app create my-app
# Or start with a blank Go app
encore app create my-app --example=hello-world
A minimal Encore Go app:
my-app/
├── encore.app # App configuration
├── go.mod # Go module
└── hello/ # A service (package with API)
└── hello.go # API endpoints
// encore.app
{
"id": "my-app"
}
This file marks the root of your Encore app. The id is your app's unique identifier.
In Encore Go, any package with an //encore:api endpoint becomes a service:
// hello/hello.go
package hello
import "context"
type Response struct {
Message string `json:"message"`
}
//encore:api public method=GET path=/hello
func Hello(ctx context.Context) (*Response, error) {
return &Response{Message: "Hello, World!"}, nil
}
# Start the development server
encore run
# Your API is now available at http://localhost:4000
# Opens the local development dashboard
encore run
# Then visit http://localhost:9400
The dashboard shows:
| Command | Description |
|---|---|
encore run | Start the local development server |
encore test | Run tests (uses go test under the hood) |
encore db shell <db> | Open a psql shell to a database |
encore gen client | Generate API client code |
encore app link | Link to an existing Encore Cloud app |
type GetUserParams struct {
ID string
}
type User struct {
ID string `json:"id"`
Name string `json:"name"`
}
//encore:api public method=GET path=/users/:id
func GetUser(ctx context.Context, params *GetUserParams) (*User, error) {
return &User{ID: params.ID, Name: "John"}, nil
}
// db.go
package hello
import "encore.dev/storage/sqldb"
var db = sqldb.NewDatabase("mydb", sqldb.DatabaseConfig{
Migrations: "./migrations",
})
Create a migration:
-- hello/migrations/1_create_table.up.sql
CREATE TABLE items (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL
);
import "encore.dev/storage/sqldb"
type Item struct {
ID int
Name string
}
func getItem(ctx context.Context, id int) (*Item, error) {
item, err := sqldb.QueryRow[Item](ctx, db, `
SELECT id, name FROM items WHERE id = $1
`, id)
if err != nil {
return nil, err
}
return item, nil
}
encore-go-api skill)encore-go-auth skill)encore-go-infrastructure skill)encore app link then git push encoreWeekly Installs
119
Repository
GitHub Stars
20
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
opencode100
gemini-cli99
codex99
claude-code92
github-copilot81
cursor78
飞书OpenAPI Explorer:探索和调用未封装的飞书原生API接口
37,900 周安装