Loading...
Loading...
Get started with Encore Go.
npx skill4agent add encoredev/skills 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# Interactive - choose from templates
encore app create my-app
# Or start with a blank Go app
encore app create my-app --example=hello-worldmy-app/
├── encore.app # App configuration
├── go.mod # Go module
└── hello/ # A service (package with API)
└── hello.go # API endpoints// encore.app
{
"id": "my-app"
}id//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
}# 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| Command | Description |
|---|---|
| Start the local development server |
| Run tests (uses |
| Open a psql shell to a database |
| Generate API client code |
| 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",
})-- 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-apiencore-go-authencore-go-infrastructureencore app linkgit push encore