mirror of
https://github.com/yudai/gotty.git
synced 2025-12-25 19:58:50 +01:00
31 lines
683 B
Go
31 lines
683 B
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
)
|
|
|
|
// RunOptions holds a set of configurations for Server.Run().
|
|
type RunOptions struct {
|
|
gracefullCtx context.Context
|
|
|
|
listener net.Listener
|
|
}
|
|
|
|
// 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
|
|
}
|
|
}
|
|
|
|
// WithListener allows the caller to override the default listener
|
|
func WithListener(l net.Listener) RunOption {
|
|
return func(options *RunOptions) {
|
|
options.listener = l
|
|
}
|
|
}
|