This commit is contained in:
2025-12-04 10:55:25 +08:00
commit 60992c1e44
19 changed files with 1058 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
package models
import "github.com/golang-jwt/jwt/v5"
type AuthorizationRequest struct {
UserID string `json:"user_id"`
Resource string `json:"resource"`
Action string `json:"action"`
}
type AuthorizationResponse struct {
Allowed bool `json:"allowed"`
Reason string `json:"reason,omitempty"`
}
type Claims struct {
UserID string `json:"user_id"`
Username string `json:"username"`
Role string `json:"role"`
jwt.RegisteredClaims
}
+26
View File
@@ -0,0 +1,26 @@
package models
import "net/http"
// FlusherPreservingResponseWriter wraps http.ResponseWriter and preserves http.Flusher for SSE endpoints.
type FlusherPreservingResponseWriter struct {
http.ResponseWriter
}
func (w *FlusherPreservingResponseWriter) Flush() {
if f, ok := w.ResponseWriter.(http.Flusher); ok {
f.Flush()
}
}
// ResponseWriter wraps http.ResponseWriter to track response size for metrics
type ResponseWriter struct {
http.ResponseWriter
Size int
}
func (rw *ResponseWriter) Write(b []byte) (int, error) {
size, err := rw.ResponseWriter.Write(b)
rw.Size += size
return size, err
}