Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "encoding/json"
- "fmt"
- "net/http"
- "github.com/remeh/sizedwaitgroup"
- )
- func main() {
- fmt.Println("Input # of times to run")
- var number int
- fmt.Scan(&number)
- fmt.Println("Input # of threads")
- var threads int
- fmt.Scan(&threads)
- swg := sizedwaitgroup.New(threads)
- for i := 0; i < number; i++ {
- swg.Add()
- go func(i int) {
- defer swg.Done()
- var data Autogenerated
- resp, err := http.Get("http://api.open-notify.org/iss-now.json")
- if err := json.NewDecoder(resp.Body).Decode(&data); err != nil { // Parse []byte to go struct pointer
- fmt.Println("Can not unmarshal JSON")
- }
- if err != nil {
- fmt.Println(err)
- }
- resp.Body.Close()
- fmt.Println("\n Longitude: ", data.IssPosition.Longitude, " Latitude:", data.IssPosition.Latitude, "Request # ", i)
- }(i)
- }
- swg.Wait()
- }
- type Autogenerated struct {
- Message string `json:"message"`
- IssPosition struct {
- Longitude string `json:"longitude"`
- Latitude string `json:"latitude"`
- } `json:"iss_position"`
- Timestamp int `json:"timestamp"`
- }
Advertisement
Add Comment
Please, Sign In to add comment