On Sun, 25 Nov 2018 at 16:54, 'Axel Wagner' via golang-nuts < golang-nuts@googlegroups.com> wrote:
> I'd suggest simply > func (b *Binlog) writeArgumentToOutput(writer writer, arg uint64) error { > /* do the writing */ } > and doing the actual conversions at the call-site. It's type-safe, > shorter, faster and more idiomatic - with the tiny downside of a `uint64()` > here and there. > > Alternatively, use reflect as it's intended to - something like > func writeArgumentToOutput(writer writer, arg interface{}) error { > rv := reflect.ValueOf(arg) > var v uint64 > if k := rv.Kind(); k >= reflect.Int && k < reflect.Uint { > I know constants are protected by the Go compatibility guarantee, doing range comparisons on reflect.Kind constants seems a bit dubious to me. Without going to the definitions, it's not clear to the reader which exact kinds are included here. I'd suggest enumerating all the expected kinds directly in a switch statement (the compiler may well optimize to a range comparison for that anyway). -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.