Documentation
¶
Index ¶
- Constants
- Variables
- func ClientIP(r *http.Request) string
- func HandleMetrics(logger *core.Logger) http.Handler
- func ReadJSON[T any](req *http.Request) (T, error)
- func RecordRequest(code int, d time.Duration)
- func RenderHTML(w http.ResponseWriter, status int, s string) error
- func RenderJSON[T any](w http.ResponseWriter, status int, obj T) error
- type ContextKey
- type HTTPServer
- type Metrics
- type MetricsReport
- type Middleware
- type ReqMetrics
- type RouterGroup
- type SessionCookie
Constants ¶
View Source
const SESSION_COOKIE_NAME = "session_token"
Variables ¶
View Source
var ErrExpiredCookie = fmt.Errorf("cookie has expired")
Functions ¶
func RecordRequest ¶
func RenderHTML ¶
func RenderHTML(w http.ResponseWriter, status int, s string) error
func RenderJSON ¶
func RenderJSON[T any](w http.ResponseWriter, status int, obj T) error
func renderJSON[T any](w http.ResponseWriter, r *http.Request, status int, obj T) error {
Types ¶
type HTTPServer ¶
type HTTPServer struct {
Logger *core.Logger
Config *core.Config
db.CuttleDB
db.AuthDB
Handler http.Handler
// Mux saves the http.ServeMux instance. This provides easier access to the
// mux without having to enforce a ref type on HTTPServer.Handler everytime.
// We can now use HTTPServer.Mux.Handle() instead of HTTPServer.Handler.(*http.ServeMux).Handle().
Mux *http.ServeMux
}
func NewHTTPServer ¶
func NewHTTPServer(logger *core.Logger, config *core.Config) HTTPServer
type Metrics ¶
func NewMetrics ¶
func NewMetrics() *Metrics
type MetricsReport ¶
type MetricsReport struct {
Start time.Time `json:"start"` // Time metrics started being gathered
End time.Time `json:"end"` // Time metrics were gathered
DurationSec float64 `json:"duration_sec"` // Duration metrics where gathered in Seconds
Requests int `json:"requests"` // Total Requests
Errors int `json:"errors"` // Total Errors
RequestsPS float64 `json:"requests_ps"` // Requests Per Second
ErrorsPS float64 `json:"errors_ps"` // Errors Per Second
MinDuration float64 `json:"min_duration"` // Minimum Duration
AvgDuration float64 `json:"avg_duration"` // Average Duration
MaxDuration float64 `json:"max_duration"` // Maximum Duration
}
func Report ¶
func Report() MetricsReport
type Middleware ¶
func APIAuthMiddleware ¶
func APIAuthMiddleware(logger *core.Logger, users db.CuttleDB) Middleware
func LoggerMiddleware ¶
func LoggerMiddleware(logger *core.Logger) Middleware
func WebAuthMiddleware ¶
type ReqMetrics ¶
type ReqMetrics struct {
ClientIP string `json:"client_ip"`
RequestTime time.Time `json:"request_time"`
Method string `json:"method"`
URI string `json:"uri"`
ResponseCode int `json:"response_code"`
ResponseSize int64 `json:"response_size"`
Referer string `json:"referer"`
UserAgent string `json:"user_agent"`
Duration time.Duration `json:"duration"`
}
func NewReqMetrics ¶
func NewReqMetrics(r *http.Request) ReqMetrics
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
func NewRouterGroup ¶
func NewRouterGroup(mux *http.ServeMux, path string, middleware ...Middleware) (*RouterGroup, error)
func (*RouterGroup) ANY ¶
func (group *RouterGroup) ANY(path string, handler http.Handler, middleware ...Middleware)
func (*RouterGroup) GET ¶
func (group *RouterGroup) GET(path string, handler http.Handler, middleware ...Middleware)
func (*RouterGroup) Group ¶
func (group *RouterGroup) Group(path string, middleware ...Middleware) *RouterGroup
type SessionCookie ¶
type SessionCookie struct {
Value string // Bearer token used to lookup JWT from AuthCache.
Path string
Expires time.Time // Cookie expiration time.
}
func GetSessionCookie ¶
func GetSessionCookie(r *http.Request) (SessionCookie, error)
func NewSessionCookie ¶
func NewSessionCookie(bearer string) (SessionCookie, error)
func NewSessionCookieFromCookie ¶
func NewSessionCookieFromCookie(cookie *http.Cookie) (SessionCookie, error)
func (SessionCookie) Delete ¶
func (s SessionCookie) Delete(w http.ResponseWriter)
func (SessionCookie) Validate ¶
func (s SessionCookie) Validate() error
func (SessionCookie) Write ¶
func (s SessionCookie) Write(w http.ResponseWriter) error
Click to show internal directories.
Click to hide internal directories.