summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@inventati.org>2020-03-15 13:05:55 +0530
committerAndinus <andinus@inventati.org>2020-03-15 13:05:55 +0530
commit5ea5932cdf7f217511c215840d634fefd13f3ba6 (patch)
treef112763d17be28d0280f3bf9948855331a1d5794
parentf69c52811c6aeb5fbbaf155e87baf4539601d8a7 (diff)
downloadcetus-5ea5932cdf7f217511c215840d634fefd13f3ba6.tar.gz
Split getting api response into a function
-rw-r--r--cmd/cetus-nasa/cetus-nasa.go25
1 files changed, 18 insertions, 7 deletions
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
+}