2024-05-19 20:48:06 +03:00
|
|
|
package ss
|
2023-12-07 16:55:23 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
)
|
|
|
|
|
2024-01-10 20:11:02 +03:00
|
|
|
type Handler interface {
|
|
|
|
Handle(c *Context)
|
2023-12-07 16:55:23 +03:00
|
|
|
}
|
|
|
|
|
2024-01-10 20:11:02 +03:00
|
|
|
// The type is used for custom-one-place implementation
|
|
|
|
// of handling.
|
2024-01-03 21:23:03 +03:00
|
|
|
type Func func(*Context)
|
2024-01-10 20:11:02 +03:00
|
|
|
func (fn Func) Handle(c *Context) {
|
|
|
|
fn(c)
|
2023-12-07 16:55:23 +03:00
|
|
|
}
|
|
|
|
|
2024-01-10 20:11:02 +03:00
|
|
|
// The wrapper for the standard http.Handler(s).
|
|
|
|
type Wrap struct {
|
2024-01-10 21:19:23 +03:00
|
|
|
UseRelUrl bool
|
2024-01-10 20:11:02 +03:00
|
|
|
HttpHandler
|
2024-01-03 21:23:03 +03:00
|
|
|
}
|
2024-01-10 20:11:02 +03:00
|
|
|
func (w Wrap) Handle(c *Context) {
|
2024-01-10 21:19:23 +03:00
|
|
|
if w.UseRelUrl {
|
|
|
|
c.R.URL = c.RelUrl
|
|
|
|
}
|
2024-01-10 20:11:02 +03:00
|
|
|
w.ServeHTTP(c.W, c.R)
|
2023-12-07 16:55:23 +03:00
|
|
|
}
|
|
|
|
|