This is how to convert any object within go, into the data structure. In our example we’re using an of Page , each with their own properties and encoding them. We’re then just printing this string to Stdout, but if we were using the net/http to create an api, we would want to write to the http writer instead.
package main import ( "encoding/json" "fmt" "log" "os" ) type Page struct { Title string Filename string Content string } type Pages []Page var pages = Pages{ Page{ "First Page", "page1.

Source link


Please enter your comment!
Please enter your name here