Use this file to discover all available pages before exploring further.
The contract template separates your business logic from transport concerns. “Transport” means how data travels - HTTP, WebSocket, or JSON-RPC. By separating these, you write your core logic once and expose it through multiple protocols automatically.
package todoimport ( "context" "fmt" "sync")// Service is the todo service.type Service struct { mu sync.RWMutex todos map[string]*Todo nextID int}// New creates a new todo service.func New() *Service { return &Service{ todos: make(map[string]*Todo), }}// Todo is a todo item.type Todo struct { ID string `json:"id"` Title string `json:"title"` Completed bool `json:"completed"`}// CreateInput is the input for creating a todo.type CreateInput struct { Title string `json:"title"`}// Create creates a new todo.func (s *Service) Create(ctx context.Context, in *CreateInput) (*Todo, error) { s.mu.Lock() defer s.mu.Unlock() s.nextID++ todo := &Todo{ ID: fmt.Sprintf("%d", s.nextID), Title: in.Title, } s.todos[todo.ID] = todo return todo, nil}// List returns all todos.func (s *Service) List(ctx context.Context) ([]*Todo, error) { s.mu.RLock() defer s.mu.RUnlock() todos := make([]*Todo, 0, len(s.todos)) for _, t := range s.todos { todos = append(todos, t) } return todos, nil}
// With input and outputfunc (s *Service) Method(ctx context.Context, in *Input) (*Output, error)// Output only (no input)func (s *Service) Method(ctx context.Context) (*Output, error)// Input only (no output)func (s *Service) Method(ctx context.Context, in *Input) error// No input or outputfunc (s *Service) Method(ctx context.Context) error
type Todo struct { ID string `json:"id" doc:"Unique identifier"` Title string `json:"title" doc:"The todo title"` Completed bool `json:"completed" doc:"Whether the todo is done"`}