Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lookup for multicodec code by string name #40

Merged
merged 1 commit into from
Mar 20, 2021
Merged

Add lookup for multicodec code by string name #40

merged 1 commit into from
Mar 20, 2021

Conversation

willscott
Copy link
Contributor

* update generate to run with local stringer
@willscott willscott requested a review from mvdan March 19, 2021 22:17
Copy link
Contributor

@mvdan mvdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I didn't add the string->Code mapping API because I didn't have an immediate need for it, and because I thought that most users would only need to know about a few input multicodec strings.

It was only a matter of time before we added this, though. I do think the old API was far too bloated, but this addition seems reasonable on its own.

FYI @warpfork

//go:generate stringer -type=Code -linecomment
//go:generate go get golang.org/x/tools/cmd/stringer
//go:generate go run golang.org/x/tools/cmd/stringer -type=Code -linecomment
//go:generate go mod tidy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever :) I personally prefer to not do hacks like these until golang/go#42088 is fixed (likely in Go 1.17), but having to remember to set up stringer is also a bit of a hack.

I also slightly lean towards not having it this way, since go generate editing or tidying the current module seems a bit surprising. No strong opinion, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do like that it works and doesn't need stringer on the user path since that's not something I want to always have.
I'll file an issue to revisit once go 1.17 is out, but leave it like this from now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow lookup of code from name
2 participants