forked from fasthttp/router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglobal.go
More file actions
81 lines (63 loc) · 1.67 KB
/
Copy pathglobal.go
File metadata and controls
81 lines (63 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package httx
import (
"io/fs"
"log/slog"
"net/http"
"time"
)
var DefaultServeMux = NewMux()
func init() {
DefaultServeMux.Use(DefaultSlogMiddleware)
}
func DefaultSlogMiddleware(next HandlerFunc) HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {
start := time.Now()
defer func() {
finish := time.Now()
slog.Info("request", "method", r.Method, "uri", r.RequestURI, "time-ms", finish.Sub(start).Milliseconds())
}()
return next(w, r)
}
}
func Handle(method, path string, handler HandlerFunc) {
DefaultServeMux.Handle(method, path, handler)
}
func GET(path string, handler HandlerFunc) {
DefaultServeMux.GET(path, handler)
}
func POST(path string, handler HandlerFunc) {
DefaultServeMux.POST(path, handler)
}
func PUT(path string, handler HandlerFunc) {
DefaultServeMux.PUT(path, handler)
}
func PATCH(path string, handler HandlerFunc) {
DefaultServeMux.PATCH(path, handler)
}
func DELETE(path string, handler HandlerFunc) {
DefaultServeMux.DELETE(path, handler)
}
func HEAD(path string, handler HandlerFunc) {
DefaultServeMux.HEAD(path, handler)
}
func CONNECT(path string, handler HandlerFunc) {
DefaultServeMux.CONNECT(path, handler)
}
func OPTIONS(path string, handler HandlerFunc) {
DefaultServeMux.OPTIONS(path, handler)
}
func TRACE(path string, handler HandlerFunc) {
DefaultServeMux.TRACE(path, handler)
}
func ANY(path string, handler HandlerFunc) {
DefaultServeMux.ANY(path, handler)
}
func Merge(path string, handler http.Handler) {
DefaultServeMux.Merge(path, handler)
}
func FS(path string, f fs.FS) {
DefaultServeMux.FS(path, f)
}
func FileSystem(path string, f http.FileSystem) {
DefaultServeMux.FileSystem(path, f)
}