Skip to content

Instantly share code, notes, and snippets.

@moraes
Last active December 10, 2015 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moraes/4454703 to your computer and use it in GitHub Desktop.
Save moraes/4454703 to your computer and use it in GitHub Desktop.
Hello World using gorilla/template
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)
}
@gregworley
Copy link

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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment