zrób poprawkę kodu dla błędu: ./prog.go:16:1: syntax error: non-declaration statement…
- User
zrób poprawkę kodu dla błędu: ./prog.go:16:1: syntax error: non-declaration statement outside function body ./prog.go:24:25: syntax error: unexpected err after top level declaration
package main
import ( "encoding/json" "fmt" "log" "net/http" )
type Article struct { Title string
json:"title"URL stringjson:"url"}funct main() { resp, err := http.Get("https://dev.to/api/articles?per_page=10") if err != nil { fmt.Println("Blad podczas pobierania artykulow:", err) return } defer response.Body.Close()
codevar articles []Article err = json.NewDecoder(resp.Body).Decode(&articles) if err != nil { fmt.Println("Blad podczas dekodowania odpowiedzi:", err) return } for i, article := range articles { fmt.Printf("Artykul %d: %s\nLink: %s\n\n", i+1, article.Title, article.URL) }}
- Assistant
package main
import ( "encoding/json" "fmt" "log" "net/http" )
type Article struct { Title string
json:"title"URL stringjson:"url"}func main() { resp, err := http.Get("https://dev.to/api/articles?per_page=10") if err != nil { fmt.Println("Blad podczas pobierania artykulow:", err) return } defer resp.Body.Close()
codevar articles []Article err = json.NewDecoder(resp.Body).Decode(&articles) if err != nil { fmt.Println("Blad podczas dekodowania odpowiedzi:", err) return } for i, article := range articles { fmt.Printf("Artykul %d: %s\nLink: %s\n\n", i+1, article.Title, article.URL) }}
- User
zmodyfikuj kod o błędy: go:12:15: syntax error: unexpected json in struct type; possibly missing semicolon or newline or } go:16:1: syntax error: non-declaration statement outside function body go:25:1: syntax error: non-declaration statement outside function body
- Assistant
package main
import ( "encoding/json" "fmt" "log" "net/http" )
type Article struct { Title string
json:"title"URL stringjson:"url"}func main() { resp, err := http.Get("https://dev.to/api/articles?per_page=10") if err != nil { fmt.Println("Blad podczas pobierania artykulow:", err) return } defer resp.Body.Close()
codevar articles []Article err = json.NewDecoder(resp.Body).Decode(&articles) if err != nil { fmt.Println("Blad podczas dekodowania odpowiedzi:", err) return } for i, article := range articles { fmt.Printf("Artykul %d: %s\nLink: %s\n\n", i+1, article.Title, article.URL) }}