3 ms·
Strategy Pattern in Go
- quectophoton 3y agoNot directly related to the article, but about this: type CommonFormatter struct { Formatter } Be very careful when using it as a short way to create custom errors. For example, an error type like this: type ErrUnexpectedValue struct { error } Can be used like: err := foo() if err != nil { // You probably want to add more info though, not just `error`. // // Can be used with `errors.As`. return &ErrUnexpectedValue{ error: err } } But, while it's convenient to write, it might be easy to use the wrong way if one is not careful with getting the types exactly right (e.g. if the returned wrapped error is a pointer or not).