summary refs log tree commit diff stats
path: root/pkg/apod/json.go
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-03-24 17:41:57 +0530
committerAndinus <andinus@nand.sh>2020-03-24 17:41:57 +0530
commit813b37d0cf7e6e371418feac56d40f48176105ba (patch)
tree2e4efd2224ff84700cbf354ea0ff75775d79a8a0 /pkg/apod/json.go
parent532c060fd97c31c28f20f6f823472247edc0c30f (diff)
downloadcetus-813b37d0cf7e6e371418feac56d40f48176105ba.tar.gz
Reinitialize project and change module url
Diffstat (limited to 'pkg/apod/json.go')
-rw-r--r--pkg/apod/json.go48
1 files changed, 0 insertions, 48 deletions
diff --git a/pkg/apod/json.go b/pkg/apod/json.go
deleted file mode 100644
index d484209..0000000
--- a/pkg/apod/json.go
+++ /dev/null
@@ -1,48 +0,0 @@
-package apod
-
-import (
-	"encoding/json"
-	"fmt"
-	"regexp"
-
-	"framagit.org/andinus/cetus/pkg/request"
-)
-
-// Res holds the response from the api.
-type Res struct {
-	Copyright      string `json:"copyright"`
-	Date           string `json:"date"`
-	Explanation    string `json:"explanation"`
-	HDURL          string `json:"hdurl"`
-	MediaType      string `json:"media_type"`
-	ServiceVersion string `json:"service_version"`
-	Title          string `json:"title"`
-	URL            string `json:"url"`
-
-	Code int    `json:"code"`
-	Msg  string `json:"msg"`
-}
-
-// UnmarshalJson will take body as input & unmarshal it to res
-func UnmarshalJson(res *Res, body string) error {
-	err := json.Unmarshal([]byte(body), res)
-	if err != nil {
-		return fmt.Errorf("UnmarshalJson failed\n%s", err.Error())
-	}
-	return nil
-}
-
-// GetJson returns json response received from the api
-func GetJson(reqInfo map[string]string) (string, error) {
-	re := regexp.MustCompile("((19|20)\\d\\d)-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])")
-	if !re.MatchString(reqInfo["date"]) {
-		return "", fmt.Errorf("%s does not match format 'YYYY-MM-DD'", reqInfo["date"])
-	}
-
-	params := make(map[string]string)
-	params["api_key"] = reqInfo["apiKey"]
-	params["date"] = reqInfo["date"]
-
-	body, err := request.GetRes(reqInfo["api"], params)
-	return string(body), err
-}