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
+}
ef='#n167'>167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208