Added URL parsing

This commit is contained in:
2024-03-27 14:06:13 +01:00
parent fff7b6ae47
commit 98e1a47328
3 changed files with 126 additions and 12 deletions

View File

@ -4,17 +4,26 @@ import "git.akyoto.dev/go/router"
// Request is an interface for HTTP requests.
type Request interface {
Host() string
Method() string
Path() string
Scheme() string
}
// request represents the HTTP request used in the given context.
type request struct {
scheme string
host string
method string
path string
params []router.Parameter
}
// Host returns the requested host.
func (req *request) Host() string {
return req.host
}
// Method returns the request method.
func (req *request) Method() string {
return req.method
@ -25,6 +34,11 @@ func (req *request) Path() string {
return req.path
}
// Scheme returns either `http`, `https` or an empty string.
func (req request) Scheme() string {
return req.scheme
}
// addParameter adds a new parameter to the request.
func (req *request) addParameter(key string, value string) {
req.params = append(req.params, router.Parameter{