Standard library / encoding/gob

encoding/gob.RegisterName()

Use an explicit wire name for an interface implementation. Choose stable names and register consistently on each endpoint. Expected stdout: '9\n'.

Formal Syntax & Structure

go syntaxgo
func RegisterName(name string, value any)

Parameters & Attributes

NameTypeDescription
namestringStable unique wire name for the registered concrete type.
valueanyConcrete value identifying a type for registration, or reflect.Value for EncodeValue.

Working Example

Example Snippetgo
package main
import (  "bytes"  "encoding/gob"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
type Item struct{ N int }
func main() {  gob.RegisterName("example/item-v1", Item{})  var buf bytes.Buffer  var v any = Item{9}  must(gob.NewEncoder(&buf).Encode(&v))  var got any  must(gob.NewDecoder(&buf).Decode(&got))  fmt.Println(got.(Item).N)}
Go Reference