// makeTplData returns the template data for backends and selected nodes.
makeTplData returns the template data for backends and selected nodes.
// makeTplData returns the template data for backends and selected nodes .
func makeTplData(local *packages.Package, tags string, nodes []Node, specBcks Backends, transBcks []Backends) (*TplData, error) {
	pkgCache := NewPkgCache(local)
	pkgCache.Add(specBcks.Package)
	unionDeps := union(specBcks, transBcks)
	err := sortInDependencyOrder(unionDeps, nodes)
	if err != nil {
		return nil, errors.Wrap(err, "error sorting in dependency order")
	}
	varMap := make(map[string]string)
	for _, dep := range unionDeps {
		varMap[dep.Type.String()] = getter2Var(dep.Getter)
	}
	var deps []TplDep
	 Additionally, if the fields they access have the same name but different
	 types, we include both but append a sequence number to the field name to
	 avoid conflicts.
	uniqVars := make(map[string]string)
	for _, dep := range unionDeps {
		d, err := makeTplDep(pkgCache, nodes, dep.Getter, dep.Type, varMap)
		if err != nil {
			return nil, err
		}
		orig := d.Var
		n := 1
		for {
			prev := uniqVars[d.Var]
			if prev == "" {
				uniqVars[d.Var] = d.Type
				break
			}
			if prev == d.Type {
				d.IsDuplicate = true
				break
			}
			d.Var = orig + strconv.Itoa(n)
			n++
		}
		deps = append(deps, *d)
	}
	tb, err := makeTplBcks(pkgCache, transBcks)
	if err != nil {
		return nil, err
	}
	bcksTypeRef, err := makeTypeRef(pkgCache, specBcks.Type)
	if err != nil {
		return nil, err
	}
	return &TplData{
		Package:      local.Name,
		Tags:         tags,
		BackendsName: specBcks.Name,
		BackendsType: bcksTypeRef,
		Imports:      pkgCache.Pkgs,
		Deps:         deps,
		TransBcks:    tb,
	}, nil
}
func makeTplData ( local * packages . Package , tags string , nodes [ ] Node , specBcks Backends , transBcks [ ] Backends ) ( * TplData , error ) { pkgCache := NewPkgCache ( local ) pkgCache . Add ( specBcks . Package ) unionDeps := union ( specBcks , transBcks ) err := sortInDependencyOrder ( unionDeps , nodes ) if err != nil { return nil , errors . Wrap ( err , " " ) } varMap := make ( map [ string ] string ) for _ , dep := range unionDeps { varMap [ dep . Type . String ( ) ] = getter2Var ( dep . Getter ) } var deps [ ] TplDep uniqVars := make ( map [ string ] string ) for _ , dep := range unionDeps { d , err := makeTplDep ( pkgCache , nodes , dep . Getter , dep . Type , varMap ) if err != nil { return nil , err } orig := d . Var n := 1 for { prev := uniqVars [ d . Var ] if prev == " " { uniqVars [ d . Var ] = d . Type break } if prev == d . Type { d . IsDuplicate = true break } d . Var = orig + strconv . Itoa ( n ) n ++ } deps = append ( deps , * d ) } tb , err := makeTplBcks ( pkgCache , transBcks ) if err != nil { return nil , err } bcksTypeRef , err := makeTypeRef ( pkgCache , specBcks . Type ) if err != nil { return nil , err } return & TplData { Package : local . Name , Tags : tags , BackendsName : specBcks . Name , BackendsType : bcksTypeRef , Imports : pkgCache . Pkgs , Deps : deps , TransBcks : tb , } , nil }
makeTplData returns the template data for backends and selected nodes.
makeTplData returns the template data for backends and selected nodes .
// TODO(neil): The deps are now sorted mostly alphabetically, but also in // dependency order. It would be nice if the Backends interface was just // sorted alphabetically. // We do a first pass to figure out what the var name for each dependency is. // This is needed to correctly construct transitive dependencies. // NOTE: union dedupes on the getter name. That ensures we don't have // multiple getters in the Backends interface with the same name. But when // we create backendsImpl, we additionally need to dedupe on the var name. // For example, Foo and GetFoo are different getters, but the fields they // access would both be called foo. That would lead to a duplicate field in // the backendsImpl struct. // // Additionally, if the fields they access have the same name but different // types, we include both but append a sequence number to the field name to // avoid conflicts.