server

package
v0.0.0-...-2966923 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RandomFailure

func RandomFailure() error

func WithConfig

func WithConfig(config Config) func(*Server)

WithConfig is a test helper for overwriting server configuration

func WithLogWriter

func WithLogWriter(w io.Writer) func(*Server)

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

func WithLogger(logger *slog.Logger) func(*Server)

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 NewConfigFromEnv() (Config, error)

func (Config) MarshalJSON

func (c Config) MarshalJSON() ([]byte, error)

func (Config) String

func (c Config) String() string

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

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

func (*Server) Close

func (s *Server) Close() error

func (*Server) DoSomethingWithEvents

func (s *Server) DoSomethingWithEvents() error

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) InDebug

func (s *Server) InDebug() bool

func (*Server) InternalPort

func (s *Server) InternalPort() int

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

func (*Server) IsStarted

func (s *Server) IsStarted() bool

func (*Server) LastError

func (s *Server) LastError() error

func (*Server) Port

func (s *Server) Port() int

Port 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

func (*Server) Serve

func (s *Server) Serve() error

Jump to

Keyboard shortcuts

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