Skip to content

Instantly share code, notes, and snippets.

@sonyarianto
Last active December 8, 2018 03:51
Show Gist options
  • Save sonyarianto/a91eb9f9b7a8784fd071a748823b918d to your computer and use it in GitHub Desktop.
Save sonyarianto/a91eb9f9b7a8784fd071a748823b918d to your computer and use it in GitHub Desktop.
Go template code - passing multiple variable
package main
import (
"github.com/julienschmidt/httprouter"
"html/template"
"log"
"net/http"
)
func Home(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
// Parse templates.
var templates = template.Must(template.New("").ParseFiles("index3.html"))
data := struct{
Name string
Age int
} { Name: "Sony AK",
Age: 35 }
// Execute template.
templates.ExecuteTemplate(w, "index3.html", data)
}
func main() {
router := httprouter.New()
router.GET("/", Home)
log.Fatal(http.ListenAndServe(":3000", router))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment