Created
August 28, 2025 19:09
-
-
Save Roemer/6a40281741d250a4222552fb37805389 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "net/http" | |
| "strings" | |
| "time" | |
| ) | |
| func main() { | |
| jsonContent, err := http.Get("https://api.egdata.app/free-games?country=US") | |
| if err != nil { | |
| fmt.Println("Error fetching JSON:", err) | |
| return | |
| } | |
| defer jsonContent.Body.Close() | |
| parsedJson := AutoGenerated{} | |
| decoder := json.NewDecoder(jsonContent.Body) | |
| if err := decoder.Decode(&parsedJson); err != nil { | |
| fmt.Println("Error decoding JSON:", err) | |
| return | |
| } | |
| offers := []Offer{} | |
| for _, item := range parsedJson { | |
| if item.Giveaway.StartDate.Before(time.Now()) { | |
| offer := Offer{ | |
| Title: item.Title, | |
| Namespace: item.Namespace, | |
| OfferId: item.ID, | |
| } | |
| for _, tag := range item.Tags { | |
| switch tag.Name { | |
| case "Windows": | |
| offer.System = "PC" | |
| offers = append(offers, offer) | |
| case "iOS": | |
| offer.System = "iOS" | |
| offers = append(offers, offer) | |
| case "Android": | |
| offer.System = "Android" | |
| offers = append(offers, offer) | |
| } | |
| } | |
| } | |
| } | |
| allOffers := "" | |
| for _, offer := range offers { | |
| fmt.Printf("%s (%s): %s\n", offer.Title, offer.System, toOfferUrl(offer.ToOffer())) | |
| allOffers += offer.ToOffer() + "&" | |
| } | |
| allOffers = strings.TrimSuffix(allOffers, "&") | |
| fmt.Printf("All Offers: %s\n", toOfferUrl(allOffers)) | |
| } | |
| func toOfferUrl(offerString string) string { | |
| return fmt.Sprintf("https://store.epicgames.com/purchase?%s#/purchase/payment-methods", offerString) | |
| } | |
| type Offer struct { | |
| Title string | |
| System string | |
| Namespace string | |
| OfferId string | |
| } | |
| func (o Offer) ToOffer() string { | |
| return fmt.Sprintf("offers=1-%s-%s", o.Namespace, o.OfferId) | |
| } | |
| type AutoGenerated []struct { | |
| ID string `json:"id"` | |
| Namespace string `json:"namespace"` | |
| Title string `json:"title"` | |
| Tags []struct { | |
| ID string `json:"id"` | |
| Name string `json:"name"` | |
| } `json:"tags"` | |
| Giveaway struct { | |
| ID string `json:"id"` | |
| Namespace string `json:"namespace"` | |
| StartDate time.Time `json:"startDate"` | |
| EndDate time.Time `json:"endDate"` | |
| Title string `json:"title"` | |
| } `json:"giveaway"` | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment