by while1malloc0 · 2y ago · 0 comments
1. The rebuf.Init function panics. I almost never want a library to call panic, and when it does, I want the library function to denote that. The convention I’ve seen most often is to start the function name with Must, so MustInit instead of Init. In this case though, I think it’d be safe to be a little more lenient in what you accept as input and trim the trailing slash.
2. I never (not almost, actually never) want library code to call any of the fmt.Print functions unless the library is explicitly for writing output, or that behavior is strictly opt in. If the library really must print things, it should take a user supplied os.Writer and write to that. Let the user control what gets printed or not.
2. Yes, Will integrate a logging library instead of fmt (https://github.com/uber-go/zap)
Ideally you want to add an option via a function or interface:
func New(optOne bool, log func(string, ...any)) {
if log == nil {
log = func(m string, a ...any) { fmt.Printf(m, a...) }
}
log("starting; optOne=%v", optOne)
}
Or something along those lines.