Closed xarg closed 9 years ago
I'm for it. On Nov 4, 2014 1:02 AM, "Alex Plugaru" notifications@github.com wrote:
I would like to propose a different configuration style. Something inspired by Dave Cheney's talk which is detailed in this post: http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
Currently the way to use the imap server (as per demo/main.go):
// Configure an IMAP server on localhost port 1193 config := imap.DefaultConfig() config.Interface = "127.0.0.1:1193" // Configure a dummy mailstore mailstore := &Mailstore{} config.Store = mailstore // Start the server server := imap.Create(config) server.Start()
Which is pretty good already, but I think that using functional options might give better results in the future. I propose an API like:
// just create a server with the default options on a random port that is free and start it s := imap.NewServer() err := s.Start()
// More advanced config m := &MailStore{} msql := &SQLStore{} auth = &AuthStore{} auth2 = &AuthStore{}
s := imap.NewServer( imap.Interface("127.0.0.1:1193", imap.TLS, stuff...), imap.Interface("127.0.0.1:1993", imap.SSL, stuff..), imap.Auth(auth), imap.Auth(auth2), imap.Mailstore(mailstore), imap.Mailstore(msql) ) err := srv.Start()
What do you think? And of course, I would implement this if I get a positive feedback.
— Reply to this email directly or view it on GitHub https://github.com/alienscience/imapsrv/issues/5.
+1, this pattern is great
Would you like to PR xarg?
I would like to propose a different configuration style. Something inspired by Dave Cheney's talk which is detailed in this post: http://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis
Currently the way to use the imap server (as per demo/main.go):
Which is pretty good already, but I think that using functional options might give better results in the future. I propose an API like:
What do you think? And of course, I would implement this if I get a positive feedback.