" + s + ""
}
func (h HtmlRender) readerImage(s string) string {
return "
"
}
func (h HtmlRender) readerLink(s string, s1 string) string {
return "
" + s1 + ""
}
func (h HtmlRender) readerHeader() string {
return ""
}
func (h HtmlRender) readerFooter() string {
return ""
}
func (h HtmlRender) readerParts(s []string) string {
return strings.Join(s, "\n")
}
type JsonRender struct {
}
func (h JsonRender) readerTitle(s string) string {
return fmt.Sprintf(`"title":"%s"`, s)
}
func (h JsonRender) readerTextBlock(s string) string {
return fmt.Sprintf(`"text":"%s"`, s)
}
func (h JsonRender) readerImage(s string) string {
return fmt.Sprintf(`"img":"%s"`, s)
}
func (h JsonRender) readerLink(s string, s1 string) string {
return fmt.Sprintf(`"link":{"hef":"%s","title":"%s"}`, s, s1)
}
func (h JsonRender) readerHeader() string {
return ""
}
func (h JsonRender) readerFooter() string {
return ""
}
func (h JsonRender) readerParts(s []string) string {
return "{" + strings.Join(s, "\n") + "}"
}
type AProduct struct {
id string
title string
desc string
image string
}
func (A AProduct) getId() string {
return A.id
}
func (A AProduct) getTitle() string {
return A.title
}
func (A AProduct) getDesc() string {
return A.desc
}
func (A AProduct) getImage() string {
return A.image
}
func main() {
a := &AProduct{
id: "123",
title: "titleasdasd",
desc: "descadsasdas",
image: "iamge asdad",
}
html := HtmlRender{}
json1 := JsonRender{}
p := Page{}
p.SetProduct(a)
p.SetReader(html)
fmt.Printf("%+v\n", p.view())
fmt.Println()
p.SetReader(json1)
fmt.Printf("%+v\n", p.view())
}
```
输出
```
titleasdasd
descadsasdas
add kart
{
"title":"titleasdasd"
"text":"descadsasdas"
"img":"iamge asdad"
"link":{"hef":"/cart/add/123","title":"add kart"}
}
```
';