From 5ea5932cdf7f217511c215840d634fefd13f3ba6 Mon Sep 17 00:00:00 2001 From: Andinus Date: Sun, 15 Mar 2020 13:05:55 +0530 Subject: Split getting api response into a function --- cmd/cetus-nasa/cetus-nasa.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'cmd/cetus-nasa') diff --git a/cmd/cetus-nasa/cetus-nasa.go b/cmd/cetus-nasa/cetus-nasa.go index 5f018cb..39b22c0 100644 --- a/cmd/cetus-nasa/cetus-nasa.go +++ b/cmd/cetus-nasa/cetus-nasa.go @@ -58,15 +58,10 @@ func main() { picturePath string apodRes nasa.APOD err error - apodInfo map[string]string ) - apodInfo = make(map[string]string) - apodInfo["api"] = api - apodInfo["apiKey"] = apiKey - apodInfo["date"] = date - - apodRes, err = nasa.APODPath(apodInfo, timeout) + // get response from api + apodRes, err = getAPODRes() if err != nil { if len(apodRes.Msg) != 0 { log.Println("Message: ", apodRes.Msg) @@ -126,3 +121,19 @@ func printDetails(apodRes nasa.APOD) { } fmt.Printf("Explanation: %s\n", apodRes.Explanation) } + +func getAPODRes() (nasa.APOD, error) { + var ( + apodRes nasa.APOD + err error + apodInfo map[string]string + ) + apodInfo = make(map[string]string) + apodInfo["api"] = api + apodInfo["apiKey"] = apiKey + apodInfo["date"] = date + + apodRes, err = nasa.APODPath(apodInfo, timeout) + + return apodRes, err +} -- cgit 1.4.1-2-gfad0