Skip to content

Instantly share code, notes, and snippets.

@foolishway
Last active April 5, 2020 02:21
Show Gist options
  • Save foolishway/6298ed7ac732b440928f45d2cba0b293 to your computer and use it in GitHub Desktop.
Save foolishway/6298ed7ac732b440928f45d2cba0b293 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/http"
)
type handler func(w http.ResponseWriter, r *http.Request)
func decorator(ft handler) handler {
return func(w http.ResponseWriter, r *http.Request) {
ft(w, r)
w.Write(([]byte)("Hello world."))
}
}
func filter(w http.ResponseWriter, r *http.Request) {
w.Write(([]byte)("add someting to response.\n"))
}
func main() {
port := ":8003"
http.HandleFunc("/", decorator(filter))
log.Fatal(http.ListenAndServe(port, nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment