-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.go
More file actions
38 lines (31 loc) · 976 Bytes
/
http.go
File metadata and controls
38 lines (31 loc) · 976 Bytes
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
package module
import (
"context"
"net/http"
)
// HTTPHandler defines the interface for HTTP request handlers
type HTTPHandler interface {
Handle(w http.ResponseWriter, r *http.Request)
}
// HTTPRouter interface for routing HTTP requests
type HTTPRouter interface {
AddRoute(method, path string, handler HTTPHandler)
}
// HTTPServer interface for HTTP server modules
type HTTPServer interface {
AddRouter(router HTTPRouter)
Start(ctx context.Context) error
Stop(ctx context.Context) error
}
// HTTPHandlerAdapter adapts an http.Handler to the HTTPHandler interface
type HTTPHandlerAdapter struct {
handler http.Handler
}
// NewHTTPHandlerAdapter creates a new adapter for an http.Handler
func NewHTTPHandlerAdapter(handler http.Handler) *HTTPHandlerAdapter {
return &HTTPHandlerAdapter{handler: handler}
}
// Handle implements the HTTPHandler interface
func (a *HTTPHandlerAdapter) Handle(w http.ResponseWriter, r *http.Request) {
a.handler.ServeHTTP(w, r)
}