Removed net/http

This commit is contained in:
2024-03-26 22:46:16 +01:00
parent f4617248d8
commit 271e1cd5bd
11 changed files with 230 additions and 629 deletions

View File

@ -1,63 +1,34 @@
package web
import (
"context"
"net/http"
)
import "git.akyoto.dev/go/router"
// Request is an interface for HTTP requests.
type Request interface {
Context() context.Context
Header(key string) string
Host() string
Method() string
Path() string
Protocol() string
Read([]byte) (int, error)
Scheme() string
}
// request represents the HTTP request used in the given context.
type request struct {
*http.Request
}
// Context returns the request context.
func (req request) Context() context.Context {
return req.Request.Context()
}
// Header returns the header value for the given key.
func (req request) Header(key string) string {
return req.Request.Header.Get(key)
method string
path string
params []router.Parameter
}
// Method returns the request method.
func (req request) Method() string {
return req.Request.Method
}
// Protocol returns the request protocol.
func (req request) Protocol() string {
return req.Request.Proto
}
// Host returns the requested host.
func (req request) Host() string {
return req.Request.Host
func (req *request) Method() string {
return req.method
}
// Path returns the requested path.
func (req request) Path() string {
return req.Request.URL.Path
func (req *request) Path() string {
return req.path
}
// // Read implements the io.Reader interface and reads the request body.
func (req request) Read(buffer []byte) (int, error) {
return req.Request.Body.Read(buffer)
}
// Scheme returns either `http` or `https`.
func (req request) Scheme() string {
return req.Request.URL.Scheme
// addParameter adds a new parameter to the request.
func (req *request) addParameter(key string, value string) {
req.params = append(req.params, router.Parameter{
Key: key,
Value: value,
})
}