Documentation
¶
Overview ¶
A package server is a package that contains the server implementation of the application.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultEnv = ServiceEnv{Name("SERVICE_NAME")}
DefaultEnv is the default environment variables to lookup the service name.
var ErrUnimplemented = errors.New("server: unimplemented")
ErrUnimplemented is returned when a listener is not implemented.
var Service = &service{}
Service is used to configure the service.
Functions ¶
Types ¶
type Listener ¶
type Listener interface {
// Start is being called on the listener
Start(context.Context, ReadyFunc, RunFunc) func() error
}
Listener is the interface to a listener, so starting and shutdown of a listener, or any routine.
type ReadyFunc ¶
type ReadyFunc func()
ReadyFunc is the function that is called by Listener to signal that it is ready and the next Listener can be called.
type RunFunc ¶
type RunFunc func(func() error)
RunFunc is a function that is called to attach more routines to the server.
type Server ¶
type Server interface {
// Run is running a new go routine
Listen(listener Listener, ready bool)
// Waits for the server to fail,
// or gracefully shutdown if context is canceled
Wait() error
// SetLimit ...
SetLimit(n int)
}
Server is the interface to be implemented to run the server.
s, ctx := WithContext(context.Background())
s.Listen(listener, false)
if err := s.Wait(); err != nil {
panic(err)
}
type ServerError ¶
type ServerError struct {
Err error
}
ServerError ...
func NewServerError ¶
func NewServerError(err error) *ServerError
NewServerError returns a new error.
func (*ServerError) Error ¶
func (s *ServerError) Error() string
Error implements the error interface.
type ServiceEnv ¶
type ServiceEnv []Name
ServiceEnv is a list of environment variables to lookup the service name.