gotty/server/run_option.go

32 lines
683 B
Go
Raw Normal View History

2017-02-26 07:37:07 +09:00
package server
import (
"context"
2025-10-25 05:05:45 -05:00
"net"
2017-02-26 07:37:07 +09:00
)
// RunOptions holds a set of configurations for Server.Run().
type RunOptions struct {
gracefullCtx context.Context
2025-10-25 05:05:45 -05:00
listener net.Listener
2017-02-26 07:37:07 +09:00
}
// RunOption is an option of Server.Run().
type RunOption func(*RunOptions)
// WithGracefullContext accepts a context to shutdown a Server
// with care for existing client connections.
func WithGracefullContext(ctx context.Context) RunOption {
return func(options *RunOptions) {
options.gracefullCtx = ctx
}
}
2025-10-25 05:05:45 -05:00
// WithListener allows the caller to override the default listener
func WithListener(l net.Listener) RunOption {
return func(options *RunOptions) {
options.listener = l
}
}