--- type.go 2014-06-18 18:26:26.000000000 -0600 +++ /tmp/type.go 2014-09-19 11:51:58.000000000 -0600 @@ -807,13 +807,15 @@ concreteTypeToName[ut.base] = name } -// Register records a type, identified by a value for that type, under its -// internal type name. That name will identify the concrete type of a value -// sent or received as an interface variable. Only types that will be -// transferred as implementations of interface values need to be registered. -// Expecting to be used only during initialization, it panics if the mapping -// between types and names is not a bijection. -func Register(value interface{}) { +// IsRegisteredName returns true if the given name has already been registered. +func IsRegisteredName(name string) bool { + registerLock.Lock() + defer registerLock.Unlock() + _, ok := nameToConcreteType[name] + return ok +} + +func internalName(value interface{}) string { // Default to printed representation for unnamed types rt := reflect.TypeOf(value) name := rt.String() @@ -851,7 +853,22 @@ } } - RegisterName(name, value) + return name +} + +// Register records a type, identified by a value for that type, under its +// internal type name. That name will identify the concrete type of a value +// sent or received as an interface variable. Only types that will be +// transferred as implementations of interface values need to be registered. +// Expecting to be used only during initialization, it panics if the mapping +// between types and names is not a bijection. +func Register(value interface{}) { + RegisterName(internalName(value), value) +} + +// IsRegistered returns true if a given type has already been registered. +func IsRegistered(value interface{}) bool { + return IsRegisteredName(internalName(value)) } func registerBasics() {