initial import

This commit is contained in:
SourceFellows
2020-08-21 06:26:40 +02:00
commit e223458dd4
423 changed files with 9871 additions and 0 deletions

View File

@ -0,0 +1,3 @@
module golang.source-fellows.com/samples/middleware
go 1.14

View File

@ -0,0 +1,28 @@
package main
import (
"log"
"net/http"
)
func businessLogic(text string) http.Handler {
myFunc := func(res http.ResponseWriter, req *http.Request) {
res.Write([]byte(text))
}
return http.HandlerFunc(myFunc)
}
func middleWare(wrapped http.Handler) http.Handler {
return http.HandlerFunc(func(re http.ResponseWriter, rq *http.Request) {
log.Println("before request")
wrapped.ServeHTTP(re, rq)
log.Println("after request")
})
}
func main() {
http.Handle("/", middleWare(businessLogic("Hello World")))
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Printf("error with server %v", err)
}
}