I am building a an application that consumes an API then also saves the json data to go lang structs then later I will make end points that will provide results for certain calculations. I have implemented consuming the API the challenging part is how to save the data in a way that go understands. Which is a proper approach?
The following is the JSON format when I make a request.
The key
I am interested in is only Time Series (1min)
JSON
{
"Meta Data": {
"1. Information": "Intraday (1min) prices and volumes",
"2. Symbol": "MSFT",
"3. Last Refreshed": "2018-05-24 16:00:00",
"4. Interval": "1min",
"5. Output Size": "Compact",
"6. Time Zone": "US/Eastern"
},
"Time Series (1min)": {
"2018-05-24 16:00:00": {
"1. open": "98.3050",
"2. high": "98.3600",
"3. low": "98.2500",
"4. close": "98.3100",
"5. volume": "2377114"
},
"2018-05-24 15:59:00": {
"1. open": "98.2900",
"2. high": "98.3300",
"3. low": "98.2900",
"4. close": "98.3000",
"5. volume": "137133"
},
"2018-05-24 15:58:00": {
"1. open": "98.2900",
"2. high": "98.3000",
"3. low": "98.2600",
"4. close": "98.2900",
"5. volume": "135875"
},
"2018-05-24 15:53:00": {
"1. open": "98.2750",
"2. high": "98.2950",
"3. low": "98.2600",
"4. close": "98.2700",
"5. volume": "77959"
}
}
}
code
package main
import (
"fmt"
"io/ioutil"
"net/http"
"github.com/jmoiron/jsonq"
)
func main() {
response, err := http.Get("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=demo")
if err != nil {
fmt.Printf("The HTTP request failed with error %s
", err)
} else {
data, _ := ioutil.ReadAll(response.Body)
// fmt.Println(string(data))
}
}