From 813b37d0cf7e6e371418feac56d40f48176105ba Mon Sep 17 00:00:00 2001 From: Andinus Date: Tue, 24 Mar 2020 17:41:57 +0530 Subject: Reinitialize project and change module url --- pkg/apod/json.go | 48 ------------------------------------------------ pkg/apod/print.go | 19 ------------------- pkg/apod/rand.go | 25 ------------------------- 3 files changed, 92 deletions(-) delete mode 100644 pkg/apod/json.go delete mode 100644 pkg/apod/print.go delete mode 100644 pkg/apod/rand.go (limited to 'pkg/apod') 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 -} diff --git a/pkg/apod/print.go b/pkg/apod/print.go deleted file mode 100644 index a087665..0000000 --- a/pkg/apod/print.go +++ /dev/null @@ -1,19 +0,0 @@ -package apod - -import ( - "fmt" -) - -// Print will print the json output -func Print(res Res) { - fmt.Printf("Title: %s\n\n", res.Title) - fmt.Printf("Copyright: %s\n", res.Copyright) - fmt.Printf("Date: %s\n\n", res.Date) - fmt.Printf("Media Type: %s\n", res.MediaType) - if res.MediaType == "image" { - fmt.Printf("URL: %s\n\n", res.HDURL) - } else { - fmt.Printf("URL: %s\n\n", res.URL) - } - fmt.Printf("Explanation: %s\n", res.Explanation) -} diff --git a/pkg/apod/rand.go b/pkg/apod/rand.go deleted file mode 100644 index cf92784..0000000 --- a/pkg/apod/rand.go +++ /dev/null @@ -1,25 +0,0 @@ -package apod - -import ( - "math/rand" - "time" -) - -// RandDate returns a random date between 1995-06-16 & today -func RandDate() string { - var ( - min int64 - max int64 - sec int64 - delta int64 - date string - ) - min = time.Date(1995, 6, 16, 0, 0, 0, 0, time.UTC).Unix() - max = time.Now().UTC().Unix() - delta = max - min - - sec = rand.Int63n(delta) + min - date = time.Unix(sec, 0).Format("2006-01-02") - - return date -} -- cgit 1.4.1-2-gfad0