Documentation ¶
Index ¶
- Variables
- func T()
- type Mode
- type Option
- func DevelopmentMode() Option
- func ListenOn(listen string) Option
- func ProductionMode() Option
- func WithLogger(logger *slog.Logger) Option
- func WithMode(mode Mode) Option
- func WithServerTimeouts(readTimeout, writeTimeout, idleTimeout time.Duration) Option
- func WithShutdownTimeout(timeout time.Duration) Option
- type Server
Constants ¶
This section is empty.
Variables ¶
var ( DefaultLoggerProduction = slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ Level: slog.LevelInfo, })) DefaultLoggerDevelopment = slog.New(tint.NewHandler(os.Stdout, &tint.Options{ Level: slog.LevelDebug, TimeFormat: time.TimeOnly, })) )
Functions ¶
Types ¶
type Option ¶
type Option func(*Server)
func DevelopmentMode ¶
func DevelopmentMode() Option
DevelopmentMode listens for file changes and restarts accordingly (as well as running go generate) and the default logger is pretty printer.
func ListenOn ¶
ListenOn the host and the port (e.g: localhost:3000 or :8080) The default value depends on the server mode: In Development = localhost:8080 (http only) In Production = 0.0.0.0:80 & 0.0.0.0:443 (if TLS is enabled)
func ProductionMode ¶
func ProductionMode() Option
ProductionMode don't listen for file changes and the default logger is a JSON logger.
func WithLogger ¶
WithLogger configures error and server logger.
func WithMode ¶
WithMode allows the user to specify the server mode by value. DevelopmentMode() and ProductionMode() options are just a syntactic sugar around this function.
func WithServerTimeouts ¶
WithServerTimeouts configures "net/http".Server ReadTimeout, WriteTimeout and IdleTimeout.
func WithShutdownTimeout ¶
WithShutdownTimeout so server doesn't exceed the provided duration after receiving a stop signal.