func()

in client/options.go [67:139]


func (refOpts *ReferenceOptions) init(opts ...ReferenceOption) error {
	for _, opt := range opts {
		opt(refOpts)
	}
	if err := defaults.Set(refOpts); err != nil {
		return err
	}

	ref := refOpts.Reference

	app := refOpts.applicationCompat
	if app != nil {
		refOpts.metaDataType = app.MetadataType
		if ref.Group == "" {
			ref.Group = app.Group
		}
		if ref.Version == "" {
			ref.Version = app.Version
		}
	}

	// init method
	methods := ref.Methods
	if length := len(methods); length > 0 {
		refOpts.methodsCompat = make([]*config.MethodConfig, length)
		for i, method := range methods {
			refOpts.methodsCompat[i] = compatMethodConfig(method)
			if err := refOpts.methodsCompat[i].Init(); err != nil {
				return err
			}
		}
	}

	// init cluster
	if ref.Cluster == "" {
		ref.Cluster = "failover"
	}

	// init registries
	if len(refOpts.registriesCompat) > 0 {
		regs := refOpts.registriesCompat
		if len(ref.RegistryIDs) <= 0 {
			ref.RegistryIDs = make([]string, len(regs))
			for key := range regs {
				ref.RegistryIDs = append(ref.RegistryIDs, key)
			}
		}
		ref.RegistryIDs = commonCfg.TranslateIds(ref.RegistryIDs)

		newRegs := make(map[string]*config.RegistryConfig)
		for _, id := range ref.RegistryIDs {
			if reg, ok := regs[id]; ok {
				newRegs[id] = reg
			}
		}
		refOpts.registriesCompat = newRegs
	}

	// init protocol
	if ref.Protocol == "" {
		ref.Protocol = constant.TriProtocol
		if refOpts.Consumer != nil && refOpts.Consumer.Protocol != "" {
			ref.Protocol = refOpts.Consumer.Protocol
		}
	}

	// init serialization
	if ref.Serialization == "" {
		ref.Serialization = constant.ProtobufSerialization
	}

	return commonCfg.Verify(refOpts)
}