You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am fairly new to Golang, so I'm unsure if this is a problem with my code, Cobra, Promptui, or something else.
I have set up a minimal repro below, using jsonplaceholder's posts endpoint. Every time I run the following command, I seem to get a different output with random lines missing.
Windows 10, Powershell, Windows Terminal.
type Post struct {
UserId int
Id int
Title string
Body string
}
var posts []Post
var postTitles []string
res, err := http.Get("https://jsonplaceholder.typicode.com/posts")
if err != nil {
log.Fatalln(err)
}
defer res.Body.Close()
responseData, err := io.ReadAll(res.Body)
if err != nil {
log.Fatalln(err)
}
err = json.Unmarshal(responseData, &posts)
if err != nil {
fmt.Println("error:", err)
}
for _, post := range posts {
postTitles = append(postTitles, post.Title)
}
prompt := promptui.Select{
Label: "Select Division",
Items: postTitles,
}
i, _, err := prompt.Run()
if err != nil {
fmt.Printf("Prompt failed %v\n", err)
return
}
fmt.Printf("Title: %q\n", posts[i].Title)
fmt.Printf("Body: %q\n", posts[i].Body)
Output on the command line:
C:\Users\hoadt\Development\cobrademo> go run main.go testcommand
v sunt aut facere repellat provident occaecati excepturi optio reprehenderit
Title: "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
Body: "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
===
C:\Users\hoadt\Development\cobrademo> go run main.go testcommand
v sunt aut facere repellat provident occaecati excepturi optio reprehenderit
Body: "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
===
C:\Users\hoadt\Development\cobrademo> go run main.go testcommand
v sunt aut facere repellat provident occaecati excepturi optio reprehenderit
Title: "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
Body: "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
===
C:\Users\hoadt\Development\cobrademo> go run main.go testcommand
v sunt aut facere repellat provident occaecati excepturi optio reprehenderit
Title: "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
Body: "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
===
C:\Users\hoadt\Development\cobrademo> go run main.go divisions
v sunt aut facere repellat provident occaecati excepturi optio reprehenderit
===
C:\Users\hoadt\Development\cobrademo> go run main.go testcommand
v sunt aut facere repellat provident occaecati excepturi optio reprehenderit
Title: "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
Body: "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
===
C:\Users\hoadt\Development\cobrademo> go run main.go testcommand
v sunt aut facere repellat provident occaecati excepturi optio reprehenderit
===
C:\Users\hoadt\Development\cobrademo> go run main.go testcommand
v sunt aut facere repellat provident occaecati excepturi optio reprehenderit
Title: "sunt aut facere repellat provident occaecati excepturi optio reprehenderit"
Body: "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
The text was updated successfully, but these errors were encountered:
I am fairly new to Golang, so I'm unsure if this is a problem with my code, Cobra, Promptui, or something else.
I have set up a minimal repro below, using jsonplaceholder's posts endpoint. Every time I run the following command, I seem to get a different output with random lines missing.
Windows 10, Powershell, Windows Terminal.
Output on the command line:
The text was updated successfully, but these errors were encountered: