ugorji / go

idiomatic codec and rpc lib for msgpack, cbor, json, etc. msgpack.org[Go]
MIT License
1.87k stars 295 forks source link

Allow disabling code-generation for individual types #139

Closed 2opremio closed 8 years ago

2opremio commented 8 years ago

This is inspired by // ffjson: skip

There are situations in which the user needs/wants to provide custom Selfers for some of the types declared in a file while still being able to automatically generate Selfers for the the rest of the types in that file.

For instance see https://github.com/weaveworks/scope/commit/23ddc1b6dd9a3f8ad3f3efa77beaaffa89a68d30

I couldn't find an acceptable way to do this with the existing implementation:

ugorji commented 8 years ago

ffjson uses comments to control behaviour. go-codec doesn't as a matter of design principle. For that reason, using comments will have a very high barrier for consideration/acceptance.

I would be willing to do a not-match flag i.e. only include types which "match" the "match" regex and "do not match" the "not-match" regex.

I understand the limitations of the golang regex package: however, we will live with it, as that is not the core of the go-codec solution.

Your options are:

Both of these are workable solutions. They are not ideal, but I think (from the POV of the design of go-codec) that using comments is a non-starter. Using comments here will be a one-off solution that feels foreign to the solution - like it was tacked on.

2opremio commented 8 years ago

I find the -nr approach very inconvenient. It requires book-keeping type-names, which is particularly bad if you are not using go generate since it involves handling type-names outside of sourcecode. But ... your project your rules :). At least it's better than breaking the files in two.

Closing in favor of #140