-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.go
47 lines (41 loc) · 1.41 KB
/
interface.go
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
39
40
41
42
43
44
45
46
47
package httphandle
import (
"log/slog"
"net/http"
)
// API is an interface for an API handler.
type API[A AppSpecific] interface {
ApplyMiddleware(h http.Handler) http.Handler
Authorize(w http.ResponseWriter, r *http.Request) (authorized bool, modified *http.Request)
ContentType() (request, response string)
HTTPMethod() string
Initialize(A) error
Respond(r *http.Request) (code int, body []byte, err error)
URLPattern() string
}
// AppSpecific is an interface for the application specific implementations.
type AppSpecific interface {
ErrorTemplate(meta TemplateRespMeta, r *http.Request, w http.ResponseWriter)
Logger() *slog.Logger
NotFound(w http.ResponseWriter, r *http.Request)
}
// General is an interface for a general handler.
type General[A AppSpecific] interface {
ApplyMiddleware(h http.Handler) http.Handler
Initialize(A) error
ServeHTTP(w http.ResponseWriter, r *http.Request)
URLPattern() string
}
// Template is an interface for a template handler.
type Template[A AppSpecific] interface {
ApplyMiddleware(h http.Handler) http.Handler
Authorize(w http.ResponseWriter, r *http.Request) (authorized bool, modified *http.Request, skipTemplate bool)
Initialize(A) error
Respond(r *http.Request) (meta TemplateRespMeta, templateData any, wrapperData WrapperData)
TemplateName() string
URLPattern() string
WrapperTemplateName() string
}
type WrapperData interface {
SetResult(result TemplateDataResult)
}