2024-03-27 14:06:13 +01:00

49 lines
967 B
Go

package web
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
}
// Path returns the requested path.
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{
Key: key,
Value: value,
})
}