Last active
December 8, 2018 03:50
-
-
Save sonyarianto/6667a480a776b2d0e31d18560521f609 to your computer and use it in GitHub Desktop.
Go template code - pass simple variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("index2.html")) | |
name := "Sony AK" | |
// Execute template. | |
templates.ExecuteTemplate(w, "index2.html", name) | |
} | |
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