Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var GitCommit string = "unknown" // Populated at build time
var Version string = "development" // Populated at build time
Functions ¶
func RunCLI ¶
func RunCLI() int
RunCLI processes command-line arguments, instantiates a new chat server, calls ListenAndServe, waits for the chat server routines to cleanup and exit, then returns an exit status code.
func RunCLIWithoutWaitingForExit ¶
func RunCLIWithoutWaitingForExit() int
RunCLIWithoutWaitingForExit processes command-line arguments, instantiates a new chat server, calls ListenAndServe, then returns an exit status code without waiting for the chat server routines to exit. This is useful for Go TestScript tests, which can avoid retaining and calling cleanup methods on the chat server.
Types ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server holds the TCP listener, configuration, and communication channels used by goroutines.
func NewServer ¶
func NewServer(options ...ServerOption) (*Server, error)
NewServer returns a *Server, including optionally specified configuration. optional parameters can be specified via With*() functional options.
Example ¶
package main import ( "fmt" chat "github.com/ivanfetch/chatserver" ) func main() { server, err := chat.NewServer(chat.WithDebugLogging(), chat.WithListenAddress(":9999")) if err != nil { panic(err) } fmt.Printf("This server has debugging enabled and is listening on %s", server.GetListenAddress()) }
Output: This server has debugging enabled and is listening on :9999
func NewServerFromArgs ¶
NewServerFromArgs returns a type *Server after processing command-line arguments.
Example ¶
server, err := NewServerFromArgs([]string{"--debug-logging", "--listen-address", ":9999"}) if err != nil { panic(err) } fmt.Printf("This server has debugging enabled and is listening on %s", server.GetListenAddress())
Output: This server has debugging enabled and is listening on :9999
func (Server) GetListenAddress ¶
GetListenAddress returns the listen address on which the chat server is listening, or intends to use, depending on whether the server is currently listening for connections.
func (*Server) HasExited ¶
HasExited returns true if the chat-server goroutines have all finished and exited. This is useful to verify cleanup is complete in a non-blocking way.
func (*Server) InitiateShutdown ¶
func (s *Server) InitiateShutdown()
InitiateShutdown starts shutting down goroutines for the chat server.
func (*Server) ListenAndServe ¶
ListenAndServe begins listening for new connections, and starts the connection-and-message-manager.
func (*Server) WaitForExit ¶
func (s *Server) WaitForExit()
WaitForExit waits for the chat server goroutines to finish.
type ServerOption ¶
ServerOption uses a function to set fields on a type Server by operating on that type as an argument. This is the "functional options" pattern, and provides optional configuration and minimizes required parameters for the constructor.
func WithDebugLogging ¶
func WithDebugLogging() ServerOption
WithDebugLogging outputs debug logs to standard error. By default, minimal informative log messages are output.
func WithListenAddress ¶
func WithListenAddress(l string) ServerOption
WithListenAddress sets the corresponding field in a type Server.
func WithLogWriter ¶
func WithLogWriter(w io.Writer) ServerOption
WithLogWriter sets the io.Writer where log output is written.