zmodyfikuj ten kod, aby pokazywał dane tylko dla tych wartości: githuhusername, userid,…
- User
zmodyfikuj ten kod, aby pokazywał dane tylko dla tych wartości: githuh_username, user_id, website_url, profile_image
package main
import ( "encoding/json" "fmt" "io/ioutil" "net/http" "time"
)
type Profile struct { ProfileViews int
json:"profile_views"Followers intjson:"followers"}type Article struct { Title string
json:"title"PageViews intjson:"page_views"Comments intjson:"comments"CommentsCount intjson:"comments_count"PublicReactionsCount intjson:"public_reactions_count"PublishedTimestamp time.Timejson:"published_timestamp"PositiveReactionsCount intjson:"positive_reactions_count"CoverImage string `json:"cover_image"` SocialImage string `json:"social_image"` CreatedAt time.Time `json:"created_at"` PublishedAt time.Time `json:"published_at"` LastCommentAt time.Time `json:"last_comment_at"` ReadingTimeMinutes int `json:"reading_time_minutes"` TagList []string `json:"tag_list"` GithubUsername string `json:"user.githuh_username"` UserID int `json:"user.user_id"` WebsiteURL string `json:"user.website_url"` ProfileImage string `json:"user.profile_image"`}
func main() { apiKey := "key" url := "https://dev.to/api/articles?username=lu"
req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Blad tworzenia zadania:", err) return}
req.Header.Set("Authorization", "Bearer "+apiKey) client := &http.Client{} resp, err := client.Do(req) if err != nil { fmt.Println("Blad wykonania zadania:", err) return } defer resp.Body.Close() if resp.StatusCode == http.StatusUnauthorized { fmt.Println("Blad uwierzytelniania. Sprawdz poprawnosc klucza API.") return } body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Blad odczytu odpowiedzi:", err) return } var articles []Article err = json.Unmarshal(body, &articles) if err != nil { // Sprawdzamy, czy otrzymalismy tablicę JSON var article Article err = json.Unmarshal(body, &article) if err != nil { fmt.Println("Blad deserializacji JSON:", err) return } // Jesli deserializacja pojedynczego obiektu się powiodla, to przypisujemy go do tablicy articles = []Article{article} } fmt.Println("Ilosc moich artykulow:", len(articles)) fmt.Println("Tytuly artykulow:") for _, article := range articles { fmt.Println("- " + article.Title) } totalPageViews := 0 totalComments := 0 for _, article := range articles { totalPageViews += article.PageViews totalComments += article.Comments fmt.Println("comments_count:", article.CommentsCount) fmt.Println("public_reactions_count:", article.PublicReactionsCount) fmt.Println("published_timestamp:", article.PublishedTimestamp) fmt.Println("positive_reactions_count:", article.PositiveReactionsCount) fmt.Println("created_at:", article.CreatedAt) fmt.Println("published_at:", article.PublishedAt) fmt.Println("last_comment_at:", article.LastCommentAt) fmt.Println("reading_time_minutes:", article.ReadingTimeMinutes) fmt.Println("tag_list:", article.TagList) fmt.Println() fmt.Println("github_username:", article.GithubUsername) fmt.Println("user_id:", article.UserID) fmt.Println("website_url:", article.WebsiteURL) fmt.Println("profile_image:", article.ProfileImage) fmt.Println("cover_image:", article.CoverImage) fmt.Println("social_image:", article.SocialImage) } fmt.Println("Ilosc wyswietlen artykulow:", totalPageViews) fmt.Println("Ilosc komentarzy:", totalComments) - Assistant
- User
go install github.com/rwcarlsen/goexif/exif@latest go: downloading github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd package github.com/rwcarlsen/goexif/exif is not a main package
- Assistant
Wygląda na to, że próbujesz zainstalować pakiet
github.com/rwcarlsen/goexif/exif, który nie jest pakietem głównym (main package). Pakiety główne są tymi, które zawierają funkcjęmain()i są przeznaczone do uruchamiania jako aplikacje. Pakiety pomocnicze lub biblioteki są instalowane przy użyciu poleceniago geti nie muszą być paczkami głównymi.Aby zainstalować pakiet
github.com/rwcarlsen/goexif/exif, musisz go zaimportować jako zależność w swoim projekcie Go. Możesz to zrobić za pomocą poleceniago getlub używając modułów Go.Przykład użycia polecenia
go get:go get github.com/rwcarlsen/goexif/exifPrzykład użycia modułów Go:
-
Utwórz nowy katalog dla swojego projektu Go.
-
Wewnątrz tego katalogu uruchom polecenie
go mod init, aby utworzyć nowy moduł Go:go mod init example.com/myproject
-
- User
go build exif1.go exif1.go:6:5: ambiguous import: found package github.com/rwcarlsen/goexif/exif in multiple modules: github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd (C:\Users\ucik\go\pkg\mod\github.com\rwcarlsen\goexif@v0.0.0-20190401172101-9e8deecbddbd\exif) github.com/rwcarlsen/goexif/exif (j:\base128\exif)
- Assistant
Błąd "ambiguous import" oznacza, że istnieje konflikt importu między dwoma różnymi modułami, które zawierają pakiet
github.com/rwcarlsen/goexif/exif.W twoim przypadku, wygląda na to, że masz dwa różne moduły, które korzystają z tego samego pakietu:
github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbdgithub.com/rwcarlsen/goexif/exifw kataloguj:\base128\exif
Aby rozwiązać ten problem, możesz spróbować jednego z następujących rozwiązań:
- Jeśli oba moduły są wymagane w twoim kodzie, możesz przemianować jeden lub oba importy, aby uniknąć konfliktu nazw:
import ( exif1 "github.com/rwcarlsen/goexif/exif" exif2 "github.com/rwcarlsen/goexif" )Wtedy będziesz musiał używać prefiksu do odwoływania się do odpowiednich funkcji i typów w każdym z tych pakietów.
- Jeśli nie potrzebujesz jednego z tych modułów, usuń go z twojego projektu i odśwież zależności za pomocą polecenia :
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.