scheme.go
func Register(scheme Scheme) {
	if scheme.Generator == nil {
		panic("must specify Generator when registering Scheme")
	}

	if scheme.Opaque && scheme.Proto&ProtoUnix != 0 {
		panic("scheme must support only Opaque or Unix protocols, not both")
	}

	// register
	if _, ok := schemeMap[scheme.Driver]; ok {
		panic(fmt.Sprintf("scheme %s already registered", scheme.Driver))
	}

	sz := &Scheme{
		Driver:    scheme.Driver,
		Generator: scheme.Generator,
		Proto:     scheme.Proto,
		Opaque:    scheme.Opaque,
		Override:  scheme.Override,
	}

	schemeMap[scheme.Driver] = sz

	// add aliases
	var hasShort bool
	for _, alias := range scheme.Aliases {
		if len(alias) == 2 {
			hasShort = true
		}
		if scheme.Driver != alias {
			registerAlias(scheme.Driver, alias, false)
		}
	}

	if !hasShort && len(scheme.Driver) > 2 {
		registerAlias(scheme.Driver, scheme.Driver[:2], false)
	}

	// ensure always at least one alias, and that if Driver is 2 characters,
	// that it gets added as well
	if len(sz.Aliases) == 0 || len(scheme.Driver) == 2 {
		sz.Aliases = append(sz.Aliases, scheme.Driver)
	}

	// sort
	sort.Sort(ss(sz.Aliases))
}
func Register(scheme Scheme) {
	if scheme.Generator == nil {
		panic("must specify Generator when registering Scheme")
	}

	if scheme.Opaque && scheme.Proto&ProtoUnix != 0 {
		panic("scheme must support only Opaque or Unix protocols, not both")
	}

	// register
	if _, ok := schemeMap[scheme.Driver]; ok {
		panic(fmt.Sprintf("scheme %s already registered", scheme.Driver))
	}

	sz := &Scheme{
		Driver:    scheme.Driver,
		Generator: scheme.Generator,
		Proto:     scheme.Proto,
		Opaque:    scheme.Opaque,
		Override:  scheme.Override,
	}

	schemeMap[scheme.Driver] = sz

	// add aliases
	var hasShort bool
	for _, alias := range scheme.Aliases {
		if len(alias) == 2 {
			hasShort = true
		}
		if scheme.Driver != alias {
			registerAlias(scheme.Driver, alias, false)
		}
	}

	if !hasShort && len(scheme.Driver) > 2 {
		registerAlias(scheme.Driver, scheme.Driver[:2], false)
	}

	// ensure always at least one alias, and that if Driver is 2 characters,
	// that it gets added as well
	if len(sz.Aliases) == 0 || len(scheme.Driver) == 2 {
		sz.Aliases = append(sz.Aliases, scheme.Driver)
	}

	// sort
	sort.Sort(ss(sz.Aliases))
}
func Register ( scheme Scheme ) { if scheme . Generator == nil { panic ( " " ) } if scheme . Opaque && scheme . Proto & ProtoUnix != 0 { panic ( " " ) } // register if _ , ok := schemeMap [ scheme . Driver ] ; ok { panic ( fmt . Sprintf ( " " , scheme . Driver ) ) } sz := & Scheme { Driver : scheme . Driver , Generator : scheme . Generator , Proto : scheme . Proto , Opaque : scheme . Opaque , Override : scheme . Override , } schemeMap [ scheme . Driver ] = sz // add aliases var hasShort bool for _ , alias := range scheme . Aliases { if len ( alias ) == 2 { hasShort = true } if scheme . Driver != alias { registerAlias ( scheme . Driver , alias , false ) } } if ! hasShort && len ( scheme . Driver ) > 2 { registerAlias ( scheme . Driver , scheme . Driver [ : 2 ] , false ) } // ensure always at least one alias, and that if Driver is 2 characters, // that it gets added as well if len ( sz . Aliases ) == 0 || len ( scheme . Driver ) == 2 { sz . Aliases = append ( sz . Aliases , scheme . Driver ) } // sort sort . Sort ( ss ( sz . Aliases ) ) }
// Register registers a Scheme.
Register registers a Scheme .