Last active
April 5, 2020 02:21
-
-
Save foolishway/6298ed7ac732b440928f45d2cba0b293 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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