Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
373 views
in Technique[技术] by (71.8m points)

go - Invalid receiver type with maps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
type typeRegistry = map[string]Typ

Is a type alias. You cannot define methods on aliases (only on the original type--but in this case map[string]Typ cannot have methods on it, so you're out of luck).

What you probably want is to create a custom type, not an alias:

type typeRegistry map[string]Typ

Then your methods will work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...