Last active
December 10, 2015 15:29
-
-
Save moraes/4454703 to your computer and use it in GitHub Desktop.
Hello World using gorilla/template
This file contains 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 test | |
import ( | |
"net/http" | |
"github.com/gorilla/template/v0" | |
) | |
func helloHandler(w http.ResponseWriter, r *http.Request) { | |
set := template.Must(new(template.Set).Parse(`{{define "hello"}}Hello, world!{{end}}`)) | |
set.Execute(w, "hello", nil) | |
} | |
func init() { | |
http.HandleFunc("/", helloHandler) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a version for app engine:
package myapp
import (
template "github.com/gorilla/template/v0"
"github.com/gorilla/mux"
"net/http"
)
func init() {
r := mux.NewRouter()
r.HandleFunc("/lightrental.html", servePage)
http.Handle("/", r)
}
func servePage(w http.ResponseWriter, r *http.Request){
set := template.Must(new(template.Set).Parse(
{{define "hello"}}Hi There{{end}}
))set.Execute(w, "hello", nil)
}