Skip to content

Commit

Permalink
API Call
Browse files Browse the repository at this point in the history
  • Loading branch information
mskKandula committed Jan 5, 2024
1 parent b2dd51f commit 456a626
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Testtttt/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package main

import (
"encoding/json"
"fmt"
"net/http"
)

type Test struct {
Name string `json:"name"`
Weather string `json:"weather"`
Status []string `json:"status"`
}

type DataCode struct {
Data []Test `json:"data"`
}

func main() {

getTemperature("dallas")

}

func getTemperature(name string) {

var dataCode DataCode

url := fmt.Sprintf("https://jsonmock.hackerrank.com/api/weather?name=%s", name)

resp, _ := http.Get(url)

json.NewDecoder(resp.Body).Decode(&dataCode)

fmt.Println(dataCode.Data[0])

}

0 comments on commit 456a626

Please sign in to comment.