Skip to content

Commit

Permalink
拆出单独middleware演示
Browse files Browse the repository at this point in the history
  • Loading branch information
boyxp committed Feb 19, 2024
1 parent 2ab2062 commit 825d5c9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions _demo/middleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import "os"
import "log"
import "net/http"
import "github.com/boyxp/nova"
import "github.com/boyxp/nova/database"
import _ "api/controller"

func main() {
database.Register("database", os.Getenv("database.dbname"), os.Getenv("database.dsn"))
nova.Listen(os.Getenv("port")).Use(logger).Run()
}

func logger(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Println("logger:", r.URL.Path)
next.ServeHTTP(w, r)
})
}

0 comments on commit 825d5c9

Please sign in to comment.