helloworld.go 868 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2014 Google Inc. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. // This example only works on Managed VMs.
  5. // +build !appengine
  6. package main
  7. import (
  8. "html/template"
  9. "net/http"
  10. "time"
  11. "google.golang.org/appengine"
  12. "google.golang.org/appengine/log"
  13. )
  14. var initTime = time.Now()
  15. func main() {
  16. http.HandleFunc("/", handle)
  17. appengine.Main()
  18. }
  19. func handle(w http.ResponseWriter, r *http.Request) {
  20. if r.URL.Path != "/" {
  21. http.NotFound(w, r)
  22. return
  23. }
  24. ctx := appengine.NewContext(r)
  25. log.Infof(ctx, "Serving the front page.")
  26. tmpl.Execute(w, time.Since(initTime))
  27. }
  28. var tmpl = template.Must(template.New("front").Parse(`
  29. <html><body>
  30. <p>
  31. Hello, World! 세상아 안녕!
  32. </p>
  33. <p>
  34. This instance has been running for <em>{{.}}</em>.
  35. </p>
  36. </body></html>
  37. `))