Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74846

How to print to HTML Template

$
0
0

How to print to HTML Template in Go? source: https://github.com/timpalpant/go-iex

I must be missing a lot in the go code and in the html template.

I am looking for a way to solve the issue by printing the values to an HTML template:

package main

import (
  "fmt""html/template""net/http""github.com/timpalpant/go-iex"
)

func process(w http.ResponseWriter, r *http.Request) {

  client := iex.NewClient(&http.Client{})

  quotes, err := client.GetTOPS([]string{"AAPL", "SPY"})
  if err != nil {
    panic(err)
  }
  var s string
  for _, quote := range quotes {
    s := fmt.Sprintf("%v: bid $%.02f (%v shares), ask $%.02f (%v shares) [as of %v]\n",
      quote.Symbol, quote.BidPrice, quote.BidSize,
      quote.AskPrice, quote.AskSize, quote.LastUpdated)
  }
  t, _ := template.ParseFiles("test.html")
  quote := s
  t.Execute(w, quote)

}

func main() {

  server := http.Server{
    Addr: "127.0.0.1:8080",
  }
  http.HandleFunc("/process", process)
  server.ListenAndServe()

}

This is the HMTL Template

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Go Web Programming</title>
  </head>
  <body>
    <ul>
    {{ range . }}
      <li>{{ . }}</li>
    {{ end}}
    </ul>
  </body>
</html>

Error:

./web.go:22:5: s declared and not used


Viewing all articles
Browse latest Browse all 74846

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>