Documentation
¶
Index ¶
- Variables
- type Addr
- type App
- func (a *App) DELETE(path string, h http.Handler)
- func (a *App) GET(path string, h http.Handler)
- func (a *App) HEAD(path string, h http.Handler)
- func (a *App) POST(path string, h http.Handler)
- func (a *App) PUT(path string, h http.Handler)
- func (a *App) RegisteGrpcService(desc *grpc.ServiceDesc, s any)
- func (a *App) Run()
- type AppOption
- type AppOptions
- type Middleware
- type PromMiddleWare
- type SLogConfig
- type StatusRecorder
- type TLSConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var LogMidddle = func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { start := time.Now() re := &StatusRecorder{ResponseWriter: w} h.ServeHTTP(re, r) slog.InfoContext( r.Context(), "http request", slog.Int("status", re.Status), slog.String("duration", time.Since(start).String()), slog.String("method", r.Method), slog.String("path", r.URL.Path), ) }) }
View Source
var RecoveryMiddle = func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { defer func() { if err := recover(); err != nil { w.WriteHeader(http.StatusInternalServerError) stack := make([]byte, 1024*8) stack = stack[:runtime.Stack(stack, false)] slog.ErrorContext(r.Context(), "panic", slog.String("path", r.URL.Path), slog.Any("error", err), slog.Any("stack", stack), ) } }() h.ServeHTTP(w, r) }) }
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) RegisteGrpcService ¶
func (a *App) RegisteGrpcService(desc *grpc.ServiceDesc, s any)
type AppOption ¶
type AppOption func(aos *AppOptions)
func WihtGrpcWeb ¶
func WithCorsOptions ¶
func WithPromAddr ¶
func WithSlogConfig ¶ added in v0.0.3
func WithSlogConfig(l *SLogConfig) AppOption
func WithTLSConfig ¶
type AppOptions ¶
type AppOptions struct {
// contains filtered or unexported fields
}
type PromMiddleWare ¶ added in v0.0.3
type PromMiddleWare struct {
// contains filtered or unexported fields
}
func MetricMiddle ¶ added in v0.0.3
func MetricMiddle(name string, buckets ...float64) *PromMiddleWare
NewMiddleware returns a new prometheus Middleware handler.
type SLogConfig ¶ added in v0.0.3
type StatusRecorder ¶ added in v0.0.3
type StatusRecorder struct { http.ResponseWriter Status int }
func (*StatusRecorder) WriteHeader ¶ added in v0.0.3
func (r *StatusRecorder) WriteHeader(status int)
Click to show internal directories.
Click to hide internal directories.