no way to easily get a defaulted config
jmhodges opened this issue · 6 comments
DefaultConfig is nice, but since it's a pointer to the struct, there's no trivial way of cloning it locally and modifying it.
Making DefaultConfig not a &Config{}
, but just a Config{}
would allow users to quickly clone and customize the DefaultConfig when they are not able to use the default muxer. (Otherwise, race conditions occur.)
Alternatively, a nice factory function NewConfig() would be good.
(Yes, you can play tricks with pointer dereferencing, but that's not great.)
Writing var x = *secureheader.DefaultConfig
seems pretty trivial.
That trick is not guaranteed to work if objects inside are complex enough and have modifications made to them on other goroutines. It's something I don't think we'd want developers to normalize around. Adding a function seems to be a trivial to avoid that.
Defining DefaultConfig with Config{…}
rather than &Config{…}
is the same trick,
but I don't want to break existing programs.
This is safe because DefaultConfig doesn't contain any pointers.
Also, what are you actually trying to do here?
Can you give an example?
Regardless of whether or not you use http.DefaultServeMux,
changing secureheader.DefaultConfig doesn't require copying it.
Closing because old and that's fine