mirror of
https://github.com/SourceFellows/gobuch.git
synced 2025-08-03 13:12:16 +02:00
initial import
This commit is contained in:
3
microservices/middleware/go.mod
Normal file
3
microservices/middleware/go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module golang.source-fellows.com/samples/middleware
|
||||
|
||||
go 1.14
|
28
microservices/middleware/main.go
Normal file
28
microservices/middleware/main.go
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user