encore-go-service
38
总安装量
38
周安装量
#5432
全站排名
安装命令
npx skills add https://github.com/encoredev/skills --skill encore-go-service
Agent 安装分布
claude-code
26
gemini-cli
25
opencode
25
codex
24
github-copilot
21
cursor
20
Skill 文档
Encore Go Service Structure
Instructions
In Encore Go, each package with an API endpoint is automatically a service. No special configuration needed.
Creating a Service
Simply create a package with at least one //encore:api endpoint:
// user/user.go
package user
import "context"
type User struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
}
//encore:api public method=GET path=/users/:id
func GetUser(ctx context.Context, params *GetUserParams) (*User, error) {
// This makes "user" a service
}
Minimal Service Structure
user/
âââ user.go # API endpoints
âââ db.go # Database (if needed)
âââ migrations/ # SQL migrations
âââ 1_create_users.up.sql
Application Patterns
Single Service (Recommended Start)
Best for new projects – start simple, split later if needed:
my-app/
âââ encore.app
âââ go.mod
âââ api.go # All endpoints
âââ db.go # Database
âââ migrations/
âââ 1_initial.up.sql
Multi-Service
For distributed systems with clear domain boundaries:
my-app/
âââ encore.app
âââ go.mod
âââ user/
â âââ user.go
â âââ db.go
â âââ migrations/
âââ order/
â âââ order.go
â âââ db.go
â âââ migrations/
âââ notification/
âââ notification.go
Large Application (System-based)
Group related services into systems:
my-app/
âââ encore.app
âââ go.mod
âââ commerce/
â âââ order/
â â âââ order.go
â âââ cart/
â â âââ cart.go
â âââ payment/
â âââ payment.go
âââ identity/
â âââ user/
â â âââ user.go
â âââ auth/
â âââ auth.go
âââ comms/
âââ email/
â âââ email.go
âââ push/
âââ push.go
Service-to-Service Calls
Just import and call the function directly – Encore handles the RPC:
package order
import (
"context"
"myapp/user" // Import the user service
)
//encore:api auth method=GET path=/orders/:id
func GetOrderWithUser(ctx context.Context, params *GetOrderParams) (*OrderWithUser, error) {
order, err := getOrder(ctx, params.ID)
if err != nil {
return nil, err
}
// This becomes an RPC call - Encore handles it
orderUser, err := user.GetUser(ctx, &user.GetUserParams{ID: order.UserID})
if err != nil {
return nil, err
}
return &OrderWithUser{Order: order, User: orderUser}, nil
}
When to Split Services
Split when you have:
| Signal | Action |
|---|---|
| Different scaling needs | Split (e.g., auth vs analytics) |
| Different deployment cycles | Split |
| Clear domain boundaries | Split |
| Shared database tables | Keep together |
| Tightly coupled logic | Keep together |
| Just organizing code | Use sub-packages, not services |
Internal Helpers (Non-Service Packages)
Create packages without //encore:api endpoints for shared code:
my-app/
âââ user/
â âââ user.go # Service (has API)
âââ order/
â âââ order.go # Service (has API)
âââ internal/
âââ util/
â âââ util.go # Not a service (no API)
âââ validation/
âââ validate.go
Guidelines
- A package becomes a service when it has
//encore:apiendpoints - Services cannot be nested within other services
- Start with one service, split when there’s a clear reason
- Cross-service calls look like regular function calls
- Each service can have its own database
- Package names should be lowercase, descriptive
- Don’t create services just for code organization – use sub-packages instead