eff_qr.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2009 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. import (
  6. "flag"
  7. "html/template"
  8. "log"
  9. "net/http"
  10. )
  11. var addr = flag.String("addr", ":1718", "http service address") // Q=17, R=18
  12. var templ = template.Must(template.New("qr").Parse(templateStr))
  13. func main() {
  14. flag.Parse()
  15. http.Handle("/", http.HandlerFunc(QR))
  16. err := http.ListenAndServe(*addr, nil)
  17. if err != nil {
  18. log.Fatal("ListenAndServe:", err)
  19. }
  20. }
  21. func QR(w http.ResponseWriter, req *http.Request) {
  22. templ.Execute(w, req.FormValue("s"))
  23. }
  24. const templateStr = `
  25. <html>
  26. <head>
  27. <title>QR Link Generator</title>
  28. </head>
  29. <body>
  30. {{if .}}
  31. <img src="http://chart.apis.google.com/chart?chs=300x300&cht=qr&choe=UTF-8&chl={{.}}" />
  32. <br>
  33. {{.}}
  34. <br>
  35. <br>
  36. {{end}}
  37. <form action="/" name=f method="GET"><input maxLength=1024 size=70
  38. name=s value="" title="Text to QR Encode"><input type=submit
  39. value="Show QR" name=qr>
  40. </form>
  41. </body>
  42. </html>
  43. `