Weather API with Go and reading a simple CSV file Jun 17, 2021 • Alen Hujdur Practical example on Go usage with CSV reader: betrokkenen.csv: "id","dossierx","dossier1","dossier2","persoon","naam","voornaam","geboortedatum","overlijdensdatum","leeftijd","geboorteplaats","burgerlijke staat","geslacht","nationaliteit","nationaal nummer","nummer_identiteitskaart","kbo_nummer","straat","nummer","bus","postcode","stad","land","telefoons","e-mails","rekeningnummer","datum laatste contact","contact frequentie","aanmaakdatum klant","sociaal statuut","fiscaal statuut","beroep","beroep","vennootvorm","beheerder","commercieel afgevaardigde","identiteitskaart vervaldatum","happy_familis","happy_you","trigoon","vip","commerciele_acties","mifid","Toestemming verwerken medische gegevens","portefeuille","actief","aantal_mifid_documenten","segment","taal" "123456789","MA","0","00","[#groepering van natuurlijke en/of rechtspersonen#]","Hujdur","Alen","00/00/0000","00/00/0000",NULL,,,,," "," ",NULL,,,,,,,NULL,NULL,NULL,NULL,NULL,"24/07/2020",NULL,NULL,NULL,NULL,,NULL,NULL,"00/00/0000","[#nee#]","[#nee#]","[#nee#]","[#nee#]","[#nee#]","[#nee#]","[#nee#]","Insudata","[#ja#]","0","E", Aa read_csv.go: package main import( "bufio" "encoding/csv" "os" "fmt" "io" ) func main(){ fmt.Println("test") f, _ := os.Open("betrokkenen.csv") r := csv.NewReader(bufio.NewReader(f)) r.FieldsPerRecord = 0 r.LazyQuotes = true f, _ = os.Create("test.txt") for { record, err := r.Read() if err == io.EOF { break } fmt.Println(record[0]) } f.Close() } Next is example on using Go to call exteral Weather API, and consume data from it: package main import ( "fmt" "io/ioutil" "net/http" ) func main(){ city :="" apiKey := "here goes your API key" fmt.Print("Enter the city: ") fmt.Scanf("%s", &city) fmt.Println(getWeather(apiKey,city)) } func getWeather(apiKey,city string) string { resp, err := http.NewRequest("GET","https://api.openweathermap.org/data/2.5/weather?appid="+apiKey+"&q="+city,nil) resp.Header.Set("Content-Type", "application/octet-stream") fmt.Println(resp.URL) client := &http.Client{} result, err := client.Do(resp) if err != nil { print(err) } defer result.Body.Close() body, err := ioutil.ReadAll(result.Body) if err != nil { print(err) } return string(body) }