Exemple #1
0
func saveBlogPosts(hash map[string]*BlogPost) {
	outcome := jsongo.Object()

	for _, v1 := range hash {
		o1 := jsongo.Object()
		contentHash := jsongo.Object()

		o1.Put("author", v1.Author)
		o1.Put("headline", v1.Headline)
		o1.Put("date", int32(v1.Date.Unix()))

		for k2, v2 := range v1.ContentHash {
			contentHash.Put(k2, v2)
		}

		o1.Put("contentHash", contentHash)
		o1.Put("brief", v1.Brief)

		outcome.Put(v1.LocalPath, o1)
	}

	ioutil.WriteFile(appConfiguration["saved_data_filename"].StringValue, []byte(outcome.String()), 0644)
}
Exemple #2
0
func toJSON(posts []WrappedBlogPost) string {
	outcome := jsongo.Array()

	for _, e := range posts {
		o := jsongo.Object()

		o.Put("Path", appConfiguration["website_root"].StringValue+e.Value.LocalPath)
		o.Put("Author", e.Value.Author)
		o.Put("Headline", e.Value.Headline)
		o.Put("Date", int32(e.Value.Date.Unix()))
		o.Put("Brief", e.Value.Brief)
		o.Put("Weight", e.Weight)

		outcome.Put(o)
	}

	return outcome.String()
}