Documentation
¶
Index ¶
- type Config
- type Server
- type TeeLogHandler
- func (t *TeeLogHandler) Enabled(ctx context.Context, l slog.Level) bool
- func (t *TeeLogHandler) Flush(w io.Writer) error
- func (t *TeeLogHandler) Handle(ctx context.Context, r slog.Record) error
- func (t *TeeLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler
- func (t *TeeLogHandler) WithGroup(name string) slog.Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Listen is the address (host:port) on which the server should listen.
Listen string
// StaticDir is the directory from which to serve static files.
StaticDir string
// BwLimit limits the read and write bandwidth (each, not combined) of
// the entire server. A string like `2m, 2mb, 2M or 2MB`, all meaning
// 2 megabytes per second.
BwLimit string
// Username for HTTP basic authentication. Empty string disables authentication.
Username string
// Password for HTTP basic authentication.
Password string
// Version is the version string of this web server app.
Version string
}
Config holds the configuration for the server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the web server instance.
type TeeLogHandler ¶
type TeeLogHandler struct {
// contains filtered or unexported fields
}
TeeLogHandler will handle logging to 2 different destinations:
- `next` (which is another `slog.Handler`, most likely one configured to write to `stdout`).
- And an in-memory string buffer which can then be written to any `io.Writer` separately.
func NewTeeLogHandler ¶
func NewTeeLogHandler(handler slog.Handler) *TeeLogHandler
NewTeeLogHandler creates and initializes a new TeeLogHandler.
func (*TeeLogHandler) Enabled ¶
Enabled just returns true since anyway the "internal" logger will write any message at any level to the buffer. The `next` logger might not actually process all messages. Enabled is used such that a `TeeLogHandler` will statisfy the `slog.Hander` interface.
func (*TeeLogHandler) Flush ¶
func (t *TeeLogHandler) Flush(w io.Writer) error
Flush will write the contents of the in-memory buffer with all the logs gathered so far to `w`. Subsequent calls to Flush will repeat all the previously written logs.