forked from warrensbox/tgswitch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
WarrensBox
authored and
WarrensBox
committed
Jun 25, 2018
0 parents
commit 5ba0546
Showing
2 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
main |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
type people struct { | ||
Number int `json:"number"` | ||
} | ||
|
||
type Repo struct { | ||
URL string `json:"url"` | ||
AssetsURL string `json:"assets_url"` | ||
UploadURL string `json:"upload_url"` | ||
HTMLURL string `json:"html_url"` | ||
ID int `json:"id"` | ||
NodeID string `json:"node_id"` | ||
TagName string `json:"tag_name"` | ||
TargetCommitish string `json:"target_commitish"` | ||
Name string `json:"name"` | ||
Draft bool `json:"draft"` | ||
Prerelease bool `json:"prerelease"` | ||
CreatedAt time.Time `json:"created_at"` | ||
PublishedAt time.Time `json:"published_at"` | ||
TarballURL string `json:"tarball_url"` | ||
ZipballURL string `json:"zipball_url"` | ||
Body string `json:"body"` | ||
Author Author `json:"author"` | ||
Assets []Assets `json:"assets"` | ||
} | ||
|
||
type Author struct { | ||
Login string `json:"login"` | ||
ID int `json:"id"` | ||
NodeID string `json:"node_id"` | ||
AvatarURL string `json:"avatar_url"` | ||
GravatarID string `json:"gravatar_id"` | ||
URL string `json:"url"` | ||
HTMLURL string `json:"html_url"` | ||
FollowersURL string `json:"followers_url"` | ||
FollowingURL string `json:"following_url"` | ||
GistsURL string `json:"gists_url"` | ||
StarredURL string `json:"starred_url"` | ||
SubscriptionsURL string `json:"subscriptions_url"` | ||
OrganizationsURL string `json:"organizations_url"` | ||
ReposURL string `json:"repos_url"` | ||
EventsURL string `json:"events_url"` | ||
ReceivedEventsURL string `json:"received_events_url"` | ||
Type string `json:"type"` | ||
SiteAdmin bool `json:"site_admin"` | ||
} | ||
|
||
type Assets struct { | ||
URL string `json:"url"` | ||
ID int `json:"id"` | ||
NodeID string `json:"node_id"` | ||
Name string `json:"name"` | ||
Label string `json:"label"` | ||
ContentType string `json:"content_type"` | ||
State string `json:"state"` | ||
Size int `json:"size"` | ||
DownloadCount int `json:"download_count"` | ||
CreatedAt time.Time `json:"created_at"` | ||
UpdatedAt time.Time `json:"updated_at"` | ||
BrowserDownloadURL string `json:"browser_download_url"` | ||
Uploader Uploader `json:"uploader"` | ||
} | ||
|
||
type Uploader struct { | ||
Login string `json:"login"` | ||
ID int `json:"id"` | ||
NodeID string `json:"node_id"` | ||
AvatarURL string `json:"avatar_url"` | ||
GravatarID string `json:"gravatar_id"` | ||
URL string `json:"url"` | ||
HTMLURL string `json:"html_url"` | ||
FollowersURL string `json:"followers_url"` | ||
FollowingURL string `json:"following_url"` | ||
GistsURL string `json:"gists_url"` | ||
StarredURL string `json:"starred_url"` | ||
SubscriptionsURL string `json:"subscriptions_url"` | ||
OrganizationsURL string `json:"organizations_url"` | ||
ReposURL string `json:"repos_url"` | ||
EventsURL string `json:"events_url"` | ||
ReceivedEventsURL string `json:"received_events_url"` | ||
Type string `json:"type"` | ||
SiteAdmin bool `json:"site_admin"` | ||
} | ||
|
||
type AutoGenerated []struct { | ||
URL string `json:"url"` | ||
AssetsURL string `json:"assets_url"` | ||
UploadURL string `json:"upload_url"` | ||
HTMLURL string `json:"html_url"` | ||
ID int `json:"id"` | ||
NodeID string `json:"node_id"` | ||
TagName string `json:"tag_name"` | ||
TargetCommitish string `json:"target_commitish"` | ||
Name string `json:"name"` | ||
Draft bool `json:"draft"` | ||
Author struct { | ||
Login string `json:"login"` | ||
ID int `json:"id"` | ||
NodeID string `json:"node_id"` | ||
AvatarURL string `json:"avatar_url"` | ||
GravatarID string `json:"gravatar_id"` | ||
URL string `json:"url"` | ||
HTMLURL string `json:"html_url"` | ||
FollowersURL string `json:"followers_url"` | ||
FollowingURL string `json:"following_url"` | ||
GistsURL string `json:"gists_url"` | ||
StarredURL string `json:"starred_url"` | ||
SubscriptionsURL string `json:"subscriptions_url"` | ||
OrganizationsURL string `json:"organizations_url"` | ||
ReposURL string `json:"repos_url"` | ||
EventsURL string `json:"events_url"` | ||
ReceivedEventsURL string `json:"received_events_url"` | ||
Type string `json:"type"` | ||
SiteAdmin bool `json:"site_admin"` | ||
} `json:"author"` | ||
Prerelease bool `json:"prerelease"` | ||
CreatedAt time.Time `json:"created_at"` | ||
PublishedAt time.Time `json:"published_at"` | ||
Assets []struct { | ||
URL string `json:"url"` | ||
ID int `json:"id"` | ||
NodeID string `json:"node_id"` | ||
Name string `json:"name"` | ||
Label string `json:"label"` | ||
Uploader struct { | ||
Login string `json:"login"` | ||
ID int `json:"id"` | ||
NodeID string `json:"node_id"` | ||
AvatarURL string `json:"avatar_url"` | ||
GravatarID string `json:"gravatar_id"` | ||
URL string `json:"url"` | ||
HTMLURL string `json:"html_url"` | ||
FollowersURL string `json:"followers_url"` | ||
FollowingURL string `json:"following_url"` | ||
GistsURL string `json:"gists_url"` | ||
StarredURL string `json:"starred_url"` | ||
SubscriptionsURL string `json:"subscriptions_url"` | ||
OrganizationsURL string `json:"organizations_url"` | ||
ReposURL string `json:"repos_url"` | ||
EventsURL string `json:"events_url"` | ||
ReceivedEventsURL string `json:"received_events_url"` | ||
Type string `json:"type"` | ||
SiteAdmin bool `json:"site_admin"` | ||
} `json:"uploader"` | ||
ContentType string `json:"content_type"` | ||
State string `json:"state"` | ||
Size int `json:"size"` | ||
DownloadCount int `json:"download_count"` | ||
CreatedAt time.Time `json:"created_at"` | ||
UpdatedAt time.Time `json:"updated_at"` | ||
BrowserDownloadURL string `json:"browser_download_url"` | ||
} `json:"assets"` | ||
TarballURL string `json:"tarball_url"` | ||
ZipballURL string `json:"zipball_url"` | ||
Body string `json:"body"` | ||
} | ||
|
||
func main() { | ||
|
||
url := "https://api.github.com/repos/warrensbox/terraform-switcher/releases" | ||
|
||
spaceClient := http.Client{ | ||
Timeout: time.Second * 2, // Maximum of 2 secs | ||
} | ||
|
||
req, err := http.NewRequest(http.MethodGet, url, nil) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
req.Header.Set("User-Agent", "spacecount-tutorial") | ||
|
||
res, getErr := spaceClient.Do(req) | ||
if getErr != nil { | ||
log.Fatal(getErr) | ||
} | ||
|
||
body, readErr := ioutil.ReadAll(res.Body) | ||
if readErr != nil { | ||
log.Fatal(readErr) | ||
} | ||
|
||
//people1 := people{} | ||
var repo []Repo | ||
jsonErr := json.Unmarshal(body, &repo) | ||
if jsonErr != nil { | ||
log.Fatal(jsonErr) | ||
} | ||
|
||
//fmt.Println(repo) | ||
|
||
for _, num := range repo { | ||
// if num == 3 { | ||
// fmt.Println("index:", i) | ||
// } | ||
if num.Prerelease == false && num.Draft == false { | ||
fmt.Println(num.Name) | ||
} | ||
|
||
} | ||
|
||
} |