|
|
|
|
|
by oogali
862 days ago
|
|
I agree that too many arguments to the constructor may have the smell of too much coupling. But if I really feel I can't avoid the need to pass a good amount of external context, I create a dedicated "options" struct and pass that into the constructor as a pointer. The purpose of the pointer (rather than pass by value) is if I want default arguments, I can pass nil. type ServerOptions struct {
logger *magic.Logger
secretKey string
}
func NewServer(options *ServerOptions) (*Server, error) {
...
}
|
|