Skip to content

Instantly share code, notes, and snippets.

@leopku
Created April 15, 2021 03:51
Show Gist options
  • Save leopku/fcae7b43fd075802533d69a9d98d093a to your computer and use it in GitHub Desktop.
Save leopku/fcae7b43fd075802533d69a9d98d093a to your computer and use it in GitHub Desktop.
func WithLimit(limit int) func(*Server) {
return func(s *Server) {
return s.setLimit(limit)
}
}
func NewServer(addr string, options ...func(*Server)) (*Server, error) {
l, err := net.Listen("tcp", addr)
if err != nil {
return nil, err
}
srv := Server{listener: 1}
for _, opt := range options {
opt(&srv)
}
return &srv, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment