diff options
author | Andinus <andinus@inventati.org> | 2020-03-16 03:43:15 +0530 |
---|---|---|
committer | Andinus <andinus@inventati.org> | 2020-03-16 03:43:15 +0530 |
commit | 799b7030fc6e2d5f6de4181948a308a1ae36c0ef (patch) | |
tree | aefd488eeab061cd02f29860449723b16b31c875 /cmd/cetus-nasa | |
parent | 8d34c93eba19472077c9fbc6686ddbc5925d1aad (diff) | |
download | cetus-799b7030fc6e2d5f6de4181948a308a1ae36c0ef.tar.gz |
Export struct fields v0.4.9
Only exported structs and fields are visible to other packages, including the encoding/json package. So you must capitalize the field names of the structs to export those fields so the Marshal func can see them
Diffstat (limited to 'cmd/cetus-nasa')
-rw-r--r-- | cmd/cetus-nasa/cetus-nasa.go | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/cmd/cetus-nasa/cetus-nasa.go b/cmd/cetus-nasa/cetus-nasa.go index fafd921..d71c41d 100644 --- a/cmd/cetus-nasa/cetus-nasa.go +++ b/cmd/cetus-nasa/cetus-nasa.go @@ -13,17 +13,17 @@ import ( ) type apod 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"` + 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"` } var ( @@ -63,8 +63,8 @@ func main() { apod := apod{} err = json.Unmarshal([]byte(body), &apod) cetus.ErrChk("body unmarshal failed", err) - if len(apod.msg) != 0 { - log.Println("Message: ", apod.msg) + if len(apod.Msg) != 0 { + log.Println("Message: ", apod.Msg) } printDetails(apod) @@ -75,11 +75,10 @@ func main() { } // if media type is an image then set background - if apod.mediaType == "image" { - err = background.Set(apod.hdURL) + if apod.MediaType == "image" { + err = background.Set(apod.HdURL) cetus.ErrChk("setting background failed", err) } - } func parseFlags() { @@ -108,19 +107,19 @@ func printDetails(apod apod) { return } if pathOnly { - cetus.PrintPath(apod.hdURL) + cetus.PrintPath(apod.HdURL) return } - fmt.Printf("Title: %s\n\n", apod.title) - fmt.Printf("Copyright: %s\n", apod.copyright) - fmt.Printf("Date: %s\n\n", apod.date) - fmt.Printf("Media Type: %s\n", apod.mediaType) - if apod.mediaType == "image" { - fmt.Printf("URL: %s\n\n", apod.hdURL) + fmt.Printf("Title: %s\n\n", apod.Title) + fmt.Printf("Copyright: %s\n", apod.Copyright) + fmt.Printf("Date: %s\n\n", apod.Date) + fmt.Printf("Media Type: %s\n", apod.MediaType) + if apod.MediaType == "image" { + fmt.Printf("URL: %s\n\n", apod.HdURL) } else { - fmt.Printf("URL: %s\n\n", apod.url) + fmt.Printf("URL: %s\n\n", apod.Url) } - fmt.Printf("Explanation: %s\n", apod.explanation) + fmt.Printf("Explanation: %s\n", apod.Explanation) } func apodBody() (string, error) { |