Directory Layout
The service/ Directory
This is where your business logic lives. Services are plain Go structs.service/todo/todo.go
- Pure Go - no HTTP or transport concerns
- Context as first parameter
- Strongly typed inputs and outputs
- Returns errors for proper handling
Method Signatures
The contract system recognizes these patterns:The app/ Directory
Sets up the server and mounts transports.app/server/server.go
- Registry - Collects all services
- Register - Adds a service under a namespace (“todo”)
- REST transport - Maps methods to HTTP endpoints
- JSON-RPC transport - Handles JSON-RPC calls
- OpenAPI - Generates documentation
app/server/config.go
The cmd/ Directory
Entry point for your service.cmd/api/main.go
How Transports Map Methods
REST Mapping
Methods are mapped to HTTP endpoints automatically:| Method | HTTP | Path |
|---|---|---|
todo.Create | POST | /api/todo |
todo.List | GET | /api/todo |
todo.Get | GET | /api/todo/ |
todo.Update | PUT | /api/todo/ |
todo.Delete | DELETE | /api/todo/ |
Create→ POST without IDList→ GET without IDGet→ GET with IDUpdate→ PUT with IDDelete→ DELETE with ID
JSON-RPC Mapping
All methods are available via JSON-RPC:Adding a New Service
1. Create the Service
service/users/users.go:
2. Register the Service
Updateapp/server/server.go:
3. Test It
Type Documentation
Add documentation with struct tags:Next Steps
Tutorial
Build a complete contract service
Contract Concepts
Deep dive into contracts