Created
April 15, 2021 03:51
-
-
Save leopku/fcae7b43fd075802533d69a9d98d093a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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