server

package
v0.8.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

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.

func New

func New(config Config) (*Server, error)

New creates a new Server instance with the given configuration.

func (*Server) Logger

func (s *Server) Logger() *slog.Logger

Logger returns the server's logger instance.

func (*Server) Serve

func (s *Server) Serve() error

Serve initializes and starts the server. Will block if the server starts successfully.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server.

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

func (t *TeeLogHandler) Enabled(ctx context.Context, l slog.Level) bool

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.

func (*TeeLogHandler) Handle

func (t *TeeLogHandler) Handle(ctx context.Context, r slog.Record) error

Handle a log record.

func (*TeeLogHandler) WithAttrs

func (t *TeeLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs is used such that a `TeeLogHandler` will statisfy the `slog.Hander` interface. Currently this is NOT implemented and just returns a __copy__ of `t` without any additional attributes.

func (*TeeLogHandler) WithGroup

func (t *TeeLogHandler) WithGroup(name string) slog.Handler

WithGroup is used such that a `TeeLogHandler` will statisfy the `slog.Hander` interface. Currently this is NOT implemented and just returns a __copy__ of `t` without the new group name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL