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-bing | |
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-bing')
-rw-r--r-- | cmd/cetus-bing/cetus-bing.go | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/cmd/cetus-bing/cetus-bing.go b/cmd/cetus-bing/cetus-bing.go index b8c397c..29ef6f4 100644 --- a/cmd/cetus-bing/cetus-bing.go +++ b/cmd/cetus-bing/cetus-bing.go @@ -13,19 +13,19 @@ import ( ) type photo struct { - startDate string `json:"startdate"` - fullStartDate string `json:"fullstartdate"` - endDate string `json:"enddate"` - url string `json:"url"` - urlBase string `json:"urlbase"` - copyright string `json:"copyright"` - copyrightLink string `json:"copyrightlink"` - title string `json:"title"` - hsh string `json:"hsh"` + StartDate string `json:"startdate"` + FullStartDate string `json:"fullstartdate"` + EndDate string `json:"enddate"` + Url string `json:"url"` + UrlBase string `json:"urlbase"` + Copyright string `json:"copyright"` + CopyrightLink string `json:"copyrightlink"` + Title string `json:"title"` + Hsh string `json:"hsh"` } type bpod struct { - photos []photo `json:"images"` + Photos []photo `json:"images"` } var ( @@ -63,16 +63,16 @@ func main() { // if random was set then bpodRes holds list of multiple // responses, choose a random response from the list - var i int = rand.Intn(len(bpod.photos)) - bpodPhoto := bpod.photos[i] + var i int = rand.Intn(len(bpod.Photos)) + bpodPhoto := bpod.Photos[i] // correct image path - bpodPhoto.url = fmt.Sprintf("%s%s", "https://www.bing.com", bpodPhoto.url) + bpodPhoto.Url = fmt.Sprintf("%s%s", "https://www.bing.com", bpodPhoto.Url) // correct date format - dt, err := time.Parse("20060102", bpodPhoto.startDate) + dt, err := time.Parse("20060102", bpodPhoto.StartDate) cetus.ErrChk("bpodPhoto.startDate parse failed", err) - bpodPhoto.startDate = dt.Format("2006-01-02") + bpodPhoto.StartDate = dt.Format("2006-01-02") printDetails(bpodPhoto) @@ -81,7 +81,7 @@ func main() { return } - err = background.Set(bpodPhoto.url) + err = background.Set(bpodPhoto.Url) cetus.ErrChk("setting background failed", err) } @@ -105,14 +105,14 @@ func printDetails(bpodPhoto photo) { return } if pathOnly { - cetus.PrintPath(bpodPhoto.url) + cetus.PrintPath(bpodPhoto.Url) return } - fmt.Printf("Title: %s\n\n", bpodPhoto.title) - fmt.Printf("Copyright: %s\n", bpodPhoto.copyright) - fmt.Printf("Copyright Link: %s\n", bpodPhoto.copyrightLink) - fmt.Printf("Date: %s\n\n", bpodPhoto.startDate) - fmt.Printf("URL: %s\n", bpodPhoto.url) + fmt.Printf("Title: %s\n\n", bpodPhoto.Title) + fmt.Printf("Copyright: %s\n", bpodPhoto.Copyright) + fmt.Printf("Copyright Link: %s\n", bpodPhoto.CopyrightLink) + fmt.Printf("Date: %s\n\n", bpodPhoto.StartDate) + fmt.Printf("URL: %s\n", bpodPhoto.Url) } func bpodBody() (string, error) { |