Documentation ¶
Index ¶
- func RandomFailure() error
- func WithConfig(config Config) func(*Server)
- func WithLogWriter(w io.Writer) func(*Server)
- func WithLogger(logger *slog.Logger) func(*Server)
- type Config
- type Server
- func (s *Server) Close() error
- func (s *Server) DoSomethingWithEvents() error
- func (s *Server) ErrorJSON(w http.ResponseWriter, r *http.Request, statusCode int, userMsg string, ...)
- func (s *Server) InDebug() bool
- func (s *Server) InternalPort() int
- func (s *Server) IsStarted() bool
- func (s *Server) LastError() error
- func (s *Server) Port() int
- func (s *Server) Serve() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RandomFailure ¶
func RandomFailure() error
func WithConfig ¶
WithConfig is a test helper for overwriting server configuration
func WithLogWriter ¶
WithLogWriter is a test helper for server configuration to override logger's writer. Typically used with the lockbuffer package for testing, allowing concurrent reads and writes, preventing races in the test suite.
func WithLogger ¶
WithLogger is a test helper for server configuration to override logger
Types ¶
type Config ¶
type Config struct { // DBHost binds to 127.0.0.1 because mysql client will try to use a socket connection over localhost // but we are typically running mysql in docker, so not exposing the socket DBHost string `default:"127.0.0.1" envconfig:"db_host"` DBUser string `default:"testuser" envconfig:"db_user"` DBPass string `default:"testuser" envconfig:"db_pass"` DBName string `default:"helloworld" envconfig:"db_name"` DBPort string `default:"3306" envconfig:"db_port"` DBCACertPath string `default:"/home/seth/ca-certificate.crt" evnconfig:"cert_path"` RequireDBUp bool `default:"false" envconfig:"require_db_up"` // Hostname binds to all interfaces so docker services can connect to this server outside of docker Hostname string `default:"0.0.0.0" envconfig:"hostname"` Port int `default:"16666" evnconfig:"port"` InternalPort int `default:"16667" envconfig:"internal_port"` EnableSocialLogin bool `default:"false" envconfig:"enable_social_login"` ShouldSecure bool `default:"false" envconfig:"should_secure"` EnableDebug bool `default:"true" envconfig:"enable_debug"` TaskExpiration time.Duration `default:"1m" envconfig:"task_expiration"` ShutdownTimeout time.Duration `default:"30s" envconfig:"shutdown_timeout"` RequestTimeout time.Duration `default:"30s" envconfig:"shutdown_timeout"` SGAPIKey string `default:"" envconfig:"sendgrid_apikey"` Version string }
func NewConfigFromEnv ¶
func (Config) MarshalJSON ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) DoSomethingWithEvents ¶
DoSomethingWithEvents is for illustrative purposes of faking during tests, showing how faked dependencies bubble up in test assertions
func (*Server) ErrorJSON ¶
func (s *Server) ErrorJSON(w http.ResponseWriter, r *http.Request, statusCode int, userMsg string, err error)
ErrorJSON prepares the user message for json format. In the event an err is present, an ERROR level log will be emitted, else INFO
func (*Server) InternalPort ¶
InternalPort polls the port for a time until a non-zero port is set. If no port is set after a time, the port will return 0. This is an artificat of spinning up dynamic servers that can bind to any port, which we leverage for testing