func()

in pkg/client/dubbo/option.go [141:182]


func (opt *valuesOpt) Action(target, val any) error {
	dubboTarget, ok := target.(*dubboTarget)
	if !ok {
		return errors.New("Target is not dubboTarget in value options")
	}
	v, ok := val.([2]any)
	if !ok {
		return errors.New("The value must be [2]interface{}")
	}
	var toVals []any
	toTypes := []string{}

	if t, tok := v[1].(string); tok && len(t) != 0 {
		toTypes = strings.Split(t, ",")
	}
	if val, vok := v[0].([]any); vok {
		toVals = val
	} else if val, ok := v[0].(string); !ok || val != "" {
		toVals = []any{v[0]}
	}
	if !(len(toTypes) != 0 && len(toTypes) == len(toVals)) {
		dubboTarget.Types = toTypes
		dubboTarget.Values = toVals
		return nil
	}
	for i := range toVals {
		trimType := strings.TrimSpace(toTypes[i])
		if _, ok = constant.JTypeMapper[trimType]; ok {
			toTypes[i] = trimType
		} else {
			return errors.Errorf("Types invalid %s", trimType)
		}
		var err error
		toVals[i], err = mapTypes(toTypes[i], toVals[i])
		if err != nil {
			return errors.WithStack(err)
		}
	}
	dubboTarget.Types = toTypes
	dubboTarget.Values = toVals
	return nil
}