package main // DO NOT EDIT: This file was generated by vugu. Please regenerate instead of editing or add additional code in a separate file. import "fmt" import "reflect" import "github.com/vugu/vjson" import "github.com/vugu/vugu" import js "github.com/vugu/vugu/js" import "encoding/json" import "net/http" import "log" type Root struct { PriceData bpi `vugu:"data"` IsLoading bool `vugu:"data"` } type bpi struct { Time struct { Updated string `json:"updated"` } `json:"time"` BPI map[string]struct { Code string `json:"code"` Symbol string `json:"symbol"` RateFloat float64 `json:"rate_float"` } `json:"bpi"` } func (c *Root) HandleClick(event *vugu.DOMEvent) { c.PriceData = bpi{} ee := event.EventEnv() go func() { ee.Lock() c.IsLoading = true ee.UnlockRender() res, err := http.Get("https://api.coindesk.com/v1/bpi/currentprice.json") if err != nil { log.Printf("Error fetch()ing: %v", err) return } defer res.Body.Close() var newb bpi err = json.NewDecoder(res.Body).Decode(&newb) if err != nil { log.Printf("Error JSON decoding: %v", err) return } ee.Lock() defer ee.UnlockRender() c.PriceData = newb c.IsLoading = false }() } func (c *Root) Build(vgin *vugu.BuildIn) (vgout *vugu.BuildOut) { vgout = &vugu.BuildOut{} var vgiterkey interface{} _ = vgiterkey var vgn *vugu.VGNode vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "div", Attr: []vugu.VGAttribute{vugu.VGAttribute{Namespace: "", Key: "class", Val: "demo"}}} vgout.Out = append(vgout.Out, vgn) // root for output { vgparent := vgn _ = vgparent vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n "} vgparent.AppendChild(vgn) if c.IsLoading { vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "div", Attr: []vugu.VGAttribute(nil)} vgparent.AppendChild(vgn) { vgparent := vgn _ = vgparent vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "Loading..."} vgparent.AppendChild(vgn) } } vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n "} vgparent.AppendChild(vgn) if len(c.PriceData.BPI) > 0 { vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "div", Attr: []vugu.VGAttribute(nil)} vgparent.AppendChild(vgn) { vgparent := vgn _ = vgparent vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n "} vgparent.AppendChild(vgn) vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "div", Attr: []vugu.VGAttribute(nil)} vgparent.AppendChild(vgn) { vgparent := vgn _ = vgparent vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "Updated: "} vgparent.AppendChild(vgn) vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "span", Attr: []vugu.VGAttribute(nil)} vgparent.AppendChild(vgn) { vghtml := fmt.Sprint(c.PriceData.Time.Updated) vgn.InnerHTML = &vghtml } } vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n "} vgparent.AppendChild(vgn) vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "ul", Attr: []vugu.VGAttribute(nil)} vgparent.AppendChild(vgn) { vgparent := vgn _ = vgparent vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n "} vgparent.AppendChild(vgn) for key, value := range c.PriceData.BPI { var vgiterkey interface{} = key _ = vgiterkey key := key _ = key value := value _ = value vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "li", Attr: []vugu.VGAttribute(nil)} vgparent.AppendChild(vgn) { vgparent := vgn _ = vgparent vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n "} vgparent.AppendChild(vgn) vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "span", Attr: []vugu.VGAttribute(nil)} vgparent.AppendChild(vgn) { vghtml := fmt.Sprint(key) vgn.InnerHTML = &vghtml } vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: " "} vgparent.AppendChild(vgn) vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "span", Attr: []vugu.VGAttribute(nil)} vgparent.AppendChild(vgn) { vghtml := fmt.Sprint(fmt.Sprint(value.Symbol, value.RateFloat)) vgn.InnerHTML = &vghtml } vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n "} vgparent.AppendChild(vgn) } } vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n "} vgparent.AppendChild(vgn) } vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n "} vgparent.AppendChild(vgn) } } vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n "} vgparent.AppendChild(vgn) vgn = &vugu.VGNode{Type: vugu.VGNodeType(3), Namespace: "", Data: "button", Attr: []vugu.VGAttribute(nil)} vgparent.AppendChild(vgn) vgn.DOMEventHandlerSpecList = append(vgn.DOMEventHandlerSpecList, vugu.DOMEventHandlerSpec{ EventType: "click", Func: func(event *vugu.DOMEvent) { c.HandleClick(event) }, // TODO: implement capture, etc. mostly need to decide syntax }) { vgparent := vgn _ = vgparent vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "Fetch Bitcoin Price Index"} vgparent.AppendChild(vgn) } vgn = &vugu.VGNode{Type: vugu.VGNodeType(1), Data: "\n"} vgparent.AppendChild(vgn) } return vgout } // 'fix' unused imports var _ fmt.Stringer var _ reflect.Type var _ vjson.RawMessage var _ js.Value