i18n_test.go 495 B

12345678910111213141516171819202122232425
  1. package i18n
  2. import (
  3. "net/http"
  4. )
  5. func HelloHandlerFunc(w http.ResponseWriter, r *http.Request) {
  6. p := Printer(r)
  7. p.Fprintf(w, "Hello, world")
  8. }
  9. // helloHandler implements http.Handler.
  10. type helloHandler struct {}
  11. func (h helloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  12. p := Printer(r)
  13. p.Fprintf(w, "Hello, world")
  14. }
  15. func ExampleWithPrinter() {
  16. http.Handle("/h", WithPrinter(helloHandler{}))
  17. http.Handle("/hf", WithPrinter(http.HandlerFunc(HelloHandlerFunc)))
  18. }