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

proposal: add x/tools/cmd/mapper #30083

drgrib opened this issue Feb 4, 2019 · 2 comments

proposal: add x/tools/cmd/mapper #30083

drgrib opened this issue Feb 4, 2019 · 2 comments


Copy link

@drgrib drgrib commented Feb 4, 2019

I can offer the tool mapper as a sort of sibling to stringer. It is part of my maps repo and can be installed using

go get -u

And used with

mapper -types string:CustomType

To generate the file map_string_customtype.go that infers its package from surrounding .go files or the current folder name if no other files are found:

package maps

func ContainsKeyStringCustomType(m map[string]CustomType, k string) bool {
	_, ok := m[k]
	return ok

func ContainsValueStringCustomType(m map[string]CustomType, v CustomType) bool {
	for _, mValue := range m {
		if mValue == v {
			return true

	return false

func GetKeysStringCustomType(m map[string]CustomType) []string {
	keys := []string{}

	for k, _ := range m {
		keys = append(keys, k)

	return keys

func GetValuesStringCustomType(m map[string]CustomType) []CustomType {
	values := []CustomType{}

	for _, v := range m {
		values = append(values, v)

	return values

func CopyStringCustomType(m map[string]CustomType) map[string]CustomType {
	copyMap := map[string]CustomType{}

	for k, v := range m {
		copyMap[k] = v

	return copyMap

I've never contributed to the go code base so I'm not sure how this all works but am happy to make this code part of the core project, which may be useful until we get generics in Go 2.0.

@gopherbot gopherbot added this to the Unreleased milestone Feb 4, 2019
Copy link

@ianlancetaylor ianlancetaylor commented Feb 5, 2019

Our usual procedure would be to make the tool available in your own repo, as you've done, and see how much pick-up it gets. If a lot of other projects start using it it will make sense to consider adding it to the x/tools repo.

@andybons andybons changed the title x/tools/cmd/mapper - Feature offer proposal: add x/tools/cmd/mapper Feb 6, 2019
Copy link

@andybons andybons commented Feb 6, 2019

Putting on hold until we have more data around usage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants