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

cmd/cue: support stringable types as map keys #2269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

addreas
Copy link

@addreas addreas commented Feb 17, 2023

Ran into a case where metacontroller/metacontroller had a map where the key was a struct that implemented encoding.TextMarshaler and encoding.TextUnmarshaler. After some confusion because it was silently dropped (until i ran cue get go --verbose), i had a look and a fix seemed not too far off.

Not super excited about this patch, as it's a bit quick and dirty, but it did seem to do the trick.

Signed-off-by: Andreas Mårtensson <andreas.martensson@svt.se>
@mvdan
Copy link
Member

mvdan commented Dec 18, 2023

Apologies that we didn't reply to this PR quickly. Do you have an example or reproducer for this case? In particular, we would need a form of regression test to go with the change, to make sure that it works as expected and isn't broken in the future.

@addreas
Copy link
Author

addreas commented Jan 15, 2024

Not sure how to create a txtar for a cue get go command, and I've almost completely forgot about this whole thing as well. But the problem was that there existed a type that I wanted to cue get go on, but it was defined as type RelativeObjectMap map[GroupVersionKind]map[string]*unstructured.Unstructured and GroupVersionKind is a struct that implements encoding.TextMarshaler and encoding.TextUnmarshaler.

The minimal case should look something like this, I guess:

package test

type Convoluted map[Key]string

type Key struct {
	ActualKey string
}

// MarshalText is implementation of  encoding.TextMarshaler
func (k Key) MarshalText() ([]byte, error) {
	return []byte(k.ActualKey), nil
}

// UnmarshalText is implementation of encoding.TextUnmarshaler
func (k *Key) UnmarshalText(text []byte) error {
	*k = Key{
		ActualKey: string(text),
	}
	return nil
}

Happy to close this unless you think it's a feature worth the effort.

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.

None yet

2 participants