// makeTplDep returns the template dependency and template imports of the dependency.
makeTplDep returns the template dependency and template imports of the dependency.
// makeTplDep returns the template dependency and template imports of the dependency .
func makeTplDep(pkgCache *PkgCache, nodes []Node, getter string, dep types.Type, varMap map[string]string) (*TplDep, error) {
	for _, node := range nodes {
		if node.Type == NodeTypeBind {
			if !types.Identical(node.BindInterface, dep) {
				continue
			}
			if err := addTypeImports(pkgCache, node.BindInterface); err != nil {
				return nil, err
			}
			implDep, err := makeTplDep(pkgCache, nodes, getter, node.BindImpl, varMap)
			if err != nil {
				return nil, err
			}
			typeRef, err := makeTypeRef(pkgCache, node.BindInterface)
			if err != nil {
				return nil, err
			}
			return &TplDep{
				Type:     typeRef,
				Var:      getter2Var(getter),
				Getter:   getter,
				Provider: implDep.Provider,
			}, nil
		} else if node.Type == NodeTypeFunc {
			if !types.Identical(node.FuncResult, dep) {
				continue
			}
			if err := addObjImports(pkgCache, node.FuncObj); err != nil {
				return nil, err
			}
			typeRef, err := makeTypeRef(pkgCache, node.FuncResult)
			if err != nil {
				return nil, errors.Wrap(err, "",
					j.MKV{"node": node.FuncResult})
			}
			providerFuncName := node.FuncObj.Name()
			params, err := getParams(node.FuncSig, varMap)
			if err != nil {
				return nil, errors.Wrap(err, "error getting params")
			}
			return &TplDep{
				Type:   typeRef,
				Var:    getter2Var(getter),
				Getter: getter,
				Provider: TplProvider{
					FuncPkg:    pkgCache.Name(node.FuncObj.Pkg()),
					FuncName:   providerFuncName,
					ReturnsErr: returnsErr(node.FuncSig),
					Params:     params,
					ErrWrapMsg: makeWrapMsg(node.FuncObj.Pkg().Path(), providerFuncName),
				},
			}, nil
		} else {
			return nil, errors.New("unsupported node type")
		}
	}
	return nil, errors.New("dep no found", j.MKV{"getter": getter, "type": dep})
}
func makeTplDep ( pkgCache * PkgCache , nodes [ ] Node , getter string , dep types . Type , varMap map [ string ] string ) ( * TplDep , error ) { for _ , node := range nodes { if node . Type == NodeTypeBind { if ! types . Identical ( node . BindInterface , dep ) { continue } if err := addTypeImports ( pkgCache , node . BindInterface ) ; err != nil { return nil , err } implDep , err := makeTplDep ( pkgCache , nodes , getter , node . BindImpl , varMap ) if err != nil { return nil , err } typeRef , err := makeTypeRef ( pkgCache , node . BindInterface ) if err != nil { return nil , err } return & TplDep { Type : typeRef , Var : getter2Var ( getter ) , Getter : getter , Provider : implDep . Provider , } , nil } else if node . Type == NodeTypeFunc { if ! types . Identical ( node . FuncResult , dep ) { continue } if err := addObjImports ( pkgCache , node . FuncObj ) ; err != nil { return nil , err } typeRef , err := makeTypeRef ( pkgCache , node . FuncResult ) if err != nil { return nil , errors . Wrap ( err , " " , j . MKV { " " : node . FuncResult } ) } providerFuncName := node . FuncObj . Name ( ) params , err := getParams ( node . FuncSig , varMap ) if err != nil { return nil , errors . Wrap ( err , " " ) } return & TplDep { Type : typeRef , Var : getter2Var ( getter ) , Getter : getter , Provider : TplProvider { FuncPkg : pkgCache . Name ( node . FuncObj . Pkg ( ) ) , FuncName : providerFuncName , ReturnsErr : returnsErr ( node . FuncSig ) , Params : params , ErrWrapMsg : makeWrapMsg ( node . FuncObj . Pkg ( ) . Path ( ) , providerFuncName ) , } , } , nil } else { return nil , errors . New ( " " ) } } return nil , errors . New ( " " , j . MKV { " " : getter , " " : dep } ) }
makeTplDep returns the template dependency and template imports of the dependency.
makeTplDep returns the template dependency and template imports of the dependency .