docs: update go sdk examples (#1393)

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2026-04-14 20:50:39 -03:00
committed by GitHub
parent 66a60afe70
commit aaf86f6055
16 changed files with 122 additions and 156 deletions

View File

@@ -34,7 +34,7 @@ func main() {
session, _ := client.CreateSession(ctx, &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
SessionID: "user-123-conversation",
Model: "gpt-5",
Model: "gpt-5.4",
})
session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "Let's discuss TypeScript generics"})
@@ -42,8 +42,8 @@ func main() {
// Session ID is preserved
fmt.Println(session.SessionID)
// Destroy session but keep data on disk
session.Destroy()
// Disconnect session but keep data on disk
session.Disconnect()
}
```
@@ -61,13 +61,13 @@ session, _ := client.ResumeSession(ctx, "user-123-conversation", &copilot.Resume
// Previous context is restored
session.SendAndWait(ctx, copilot.MessageOptions{Prompt: "What were we discussing?"})
session.Destroy()
session.Disconnect()
```
### Listing available sessions
```go
sessions, _ := client.ListSessions(ctx)
sessions, _ := client.ListSessions(ctx, nil)
for _, s := range sessions {
fmt.Println("Session:", s.SessionID)
}
@@ -85,8 +85,8 @@ client.DeleteSession(ctx, "user-123-conversation")
```go
messages, _ := session.GetMessages(ctx)
for _, msg := range messages {
if msg.Data.Content != nil {
fmt.Printf("[%s] %s\n", msg.Type, *msg.Data.Content)
if d, ok := msg.Data.(*copilot.AssistantMessageData); ok {
fmt.Printf("[assistant.message] %s\n", d.Content)
}
}
```