當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Node.Value方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry-incubator/spiff/yaml.Node.Value方法的典型用法代碼示例。如果您正苦於以下問題:Golang Node.Value方法的具體用法?Golang Node.Value怎麽用?Golang Node.Value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry-incubator/spiff/yaml.Node的用法示例。


在下文中一共展示了Node.Value方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: flow

func flow(root yaml.Node, env Environment, shouldOverride bool) yaml.Node {
	if root == nil {
		return root
	}

	switch val := root.Value().(type) {
	case map[string]yaml.Node:
		return flowMap(root, env)

	case []yaml.Node:
		return flowList(root, env)

	case dynaml.Expression:
		result, ok := val.Evaluate(env)
		if !ok {
			return root
		}

		return result
	}

	if shouldOverride {
		overridden, found := env.FindInStubs(env.Path)
		if found {
			return overridden
		}
	}

	_, ok := root.Value().(string)
	if ok {
		return flowString(root, env)
	}

	return root
}
開發者ID:rdgallagher,項目名稱:spiff,代碼行數:35,代碼來源:flow.go

示例2: flowMap

func flowMap(root yaml.Node, env Environment) yaml.Node {
	rootMap := root.Value().(map[string]yaml.Node)

	env = env.WithScope(rootMap)

	newMap := make(map[string]yaml.Node)

	sortedKeys := getSortedKeys(rootMap)

	// iteration order matters for the "<<" operator, it must be the first key in the map that is handled
	for i := range sortedKeys {
		key := sortedKeys[i]
		val := rootMap[key]

		if key == "<<" {
			base := flow(val, env, true)
			baseMap, ok := base.Value().(map[string]yaml.Node)
			if ok {
				for k, v := range baseMap {
					newMap[k] = v
				}
			}

			continue
		}

		newMap[key] = flow(val, env.WithPath(key), true)
	}

	return yaml.NewNode(newMap, root.SourceName())
}
開發者ID:vincentmisquez,項目名稱:spiff,代碼行數:31,代碼來源:flow.go

示例3: simpleMergeCompatibilityCheck

/*
 * compatibility issue. A single merge node was always optional
 * means: <<: (( merge )) == <<: (( merge || nil ))
 * the first pass, just parses the dynaml
 * only the second pass, evaluates a dynaml node!
 */
func simpleMergeCompatibilityCheck(initial bool, node yaml.Node) bool {
	if !initial {
		merge, ok := node.Value().(dynaml.MergeExpr)
		return ok && !merge.Required
	}
	return false
}
開發者ID:gstackio,項目名稱:spiff,代碼行數:13,代碼來源:flow.go

示例4: flowMap

func flowMap(root yaml.Node, env Environment) yaml.Node {
	rootMap := root.Value().(map[string]yaml.Node)

	env = env.WithScope(rootMap)

	newMap := make(map[string]yaml.Node)

	for key, val := range rootMap {
		if key == "<<" {
			base := flow(val, env, true)
			baseMap, ok := base.Value().(map[string]yaml.Node)
			if ok {
				for k, v := range baseMap {
					newMap[k] = v
				}
			}

			continue
		}

		newMap[key] = flow(val, env.WithPath(key), true)
	}

	return yaml.NewNode(newMap, root.SourceName())
}
開發者ID:rdgallagher,項目名稱:spiff,代碼行數:25,代碼來源:flow.go

示例5: isExpression

func isExpression(node yaml.Node) bool {
	if node == nil {
		return false
	}
	_, ok := node.Value().(Expression)
	return ok
}
開發者ID:gstackio,項目名稱:spiff,代碼行數:7,代碼來源:unresolved_check.go

示例6: ProcessKeyTag

func ProcessKeyTag(val yaml.Node) (yaml.Node, string) {
	keyName := ""

	m, ok := val.Value().(map[string]yaml.Node)
	if ok {
		found := false
		for key, _ := range m {
			split := strings.Index(key, ":")
			if split > 0 {
				if key[:split] == "key" {
					keyName = key[split+1:]
					found = true
				}
			}
		}
		if found {
			newMap := make(map[string]yaml.Node)
			for key, v := range m {
				split := strings.Index(key, ":")
				if split > 0 {
					if key[:split] == "key" {
						key = key[split+1:]
					}
				}
				newMap[key] = v
			}
			return yaml.SubstituteNode(newMap, val), keyName
		}
	}
	return val, keyName
}
開發者ID:gstackio,項目名稱:spiff,代碼行數:31,代碼來源:flow.go

示例7: flowList

func flowList(root yaml.Node, env Environment) yaml.Node {
	rootList := root.Value().([]yaml.Node)

	debug.Debug("HANDLE LIST %v\n", env.Path)
	merged, process, replaced, redirectPath, keyName := processMerges(root, rootList, env)

	if process {

		newList := []yaml.Node{}
		if len(redirectPath) > 0 {
			env = env.RedirectOverwrite(redirectPath)
		}
		for idx, val := range merged {
			step := stepName(idx, val, keyName)
			debug.Debug("  step %s\n", step)
			newList = append(newList, flow(val, env.WithPath(step), false))
		}

		merged = newList
	}

	if keyName != "" {
		root = yaml.KeyNameNode(root, keyName)
	}
	debug.Debug("LIST DONE (%s)%v\n", root.KeyName(), env.Path)
	if replaced {
		return yaml.ReplaceNode(merged, root, redirectPath)
	}
	if len(redirectPath) > 0 {
		return yaml.RedirectNode(merged, root, redirectPath)
	}
	return yaml.SubstituteNode(merged, root)
}
開發者ID:gstackio,項目名稱:spiff,代碼行數:33,代碼來源:flow.go

示例8: isResolved

func isResolved(node yaml.Node) bool {
	if node == nil {
		return true
	}
	switch node.Value().(type) {
	case Expression:
		return false
	case []yaml.Node:
		for _, n := range node.Value().([]yaml.Node) {
			if !isResolved(n) {
				return false
			}
		}
		return true
	case map[string]yaml.Node:
		for _, n := range node.Value().(map[string]yaml.Node) {
			if !isResolved(n) {
				return false
			}
		}
		return true

	case string:
		if yaml.EmbeddedDynaml(node) != nil {
			return false
		}
		return true
	default:
		return true
	}
}
開發者ID:gstackio,項目名稱:spiff,代碼行數:31,代碼來源:unresolved_check.go

示例9: FindUnresolvedNodes

func FindUnresolvedNodes(root yaml.Node, context ...string) (nodes []UnresolvedNode) {
	if root == nil {
		return nodes
	}

	switch val := root.Value().(type) {
	case map[string]yaml.Node:
		for key, val := range val {
			nodes = append(
				nodes,
				FindUnresolvedNodes(val, addContext(context, key)...)...,
			)
		}

	case []yaml.Node:
		for i, val := range val {
			context := addContext(context, fmt.Sprintf("[%d]", i))

			nodes = append(
				nodes,
				FindUnresolvedNodes(val, context...)...,
			)
		}

	case Expression:
		var path []string
		switch val := root.Value().(type) {
		case AutoExpr:
			path = val.Path
		case MergeExpr:
			path = val.Path
		}

		nodes = append(nodes, UnresolvedNode{
			Node:    root,
			Context: context,
			Path:    path,
		})

	case string:
		if yaml.EmbeddedDynaml(root) != nil {
			nodes = append(nodes, UnresolvedNode{
				Node:    yaml.IssueNode(root, "unparseable expression"),
				Context: context,
				Path:    []string{},
			})
		}
	}

	return nodes
}
開發者ID:gstackio,項目名稱:spiff,代碼行數:51,代碼來源:unresolved_check.go

示例10: flowList

func flowList(root yaml.Node, env Environment) yaml.Node {
	rootList := root.Value().([]yaml.Node)

	merged := processMerges(rootList, env)

	newList := []yaml.Node{}

	for idx, val := range merged {
		step := stepName(idx, val)
		newList = append(newList, flow(val, env.WithPath(step), false))
	}

	return yaml.NewNode(newList, root.SourceName())
}
開發者ID:rdgallagher,項目名稱:spiff,代碼行數:14,代碼來源:flow.go

示例11: flowString

func flowString(root yaml.Node, env Environment) yaml.Node {
	rootString := root.Value().(string)

	sub := embeddedDynaml.FindStringSubmatch(rootString)
	if sub == nil {
		return root
	}

	expr, err := dynaml.Parse(sub[1], env.Path)
	if err != nil {
		return root
	}

	return yaml.NewNode(expr, root.SourceName())
}
開發者ID:rdgallagher,項目名稱:spiff,代碼行數:15,代碼來源:flow.go

示例12: findUnresolvedNodes

func findUnresolvedNodes(root yaml.Node, context ...string) (nodes []UnresolvedNode) {
	if root == nil {
		return nodes
	}

	switch val := root.Value().(type) {
	case map[string]yaml.Node:
		for key, val := range val {
			nodes = append(
				nodes,
				findUnresolvedNodes(val, addContext(context, key)...)...,
			)
		}

	case []yaml.Node:
		for i, val := range val {
			context := addContext(context, fmt.Sprintf("[%d]", i))

			nodes = append(
				nodes,
				findUnresolvedNodes(val, context...)...,
			)
		}

	case dynaml.Expression:
		nodes = append(nodes, UnresolvedNode{
			Node:    root,
			Context: context,
		})
	}

	return nodes
}
開發者ID:rdgallagher,項目名稱:spiff,代碼行數:33,代碼來源:unresolved_check.go

示例13: compare

func compare(a, b yaml.Node, path []string) []Diff {
	mismatch := Diff{A: a, B: b, Path: path}

	switch av := a.Value().(type) {
	case map[string]yaml.Node:
		switch bv := b.Value().(type) {
		case map[string]yaml.Node:
			return compareMap(av, bv, path)

		case []yaml.Node:
			toMap := listToMap(bv)

			if toMap != nil {
				return compareMap(av, toMap, path)
			} else {
				return []Diff{mismatch}
			}

		default:
			return []Diff{mismatch}
		}

	case []yaml.Node:
		switch bv := b.Value().(type) {
		case []yaml.Node:
			return compareList(av, bv, path)
		default:
			return []Diff{mismatch}
		}

	default:
		atype := reflect.TypeOf(a)
		btype := reflect.TypeOf(b)

		if atype != btype {
			return []Diff{mismatch}
		}

		if av != b.Value() {
			return []Diff{Diff{A: a, B: b, Path: path}}
		}
	}

	return []Diff{}
}
開發者ID:gstackio,項目名稱:spiff,代碼行數:45,代碼來源:compare.go

示例14: isLocallyResolved

func isLocallyResolved(node yaml.Node) bool {
	switch v := node.Value().(type) {
	case Expression:
		return false
	case map[string]yaml.Node:
		if !yaml.IsMapResolved(v) {
			return false
		}
	case []yaml.Node:
		if !yaml.IsListResolved(v) {
			return false
		}
	default:
	}

	return true
}
開發者ID:gstackio,項目名稱:spiff,代碼行數:17,代碼來源:unresolved_check.go

示例15: concatenateStringAndInt

func concatenateStringAndInt(a yaml.Node, b yaml.Node) (string, bool) {
	aString, aOk := a.Value().(string)
	if aOk {
		bString, bOk := b.Value().(string)
		if bOk {
			return aString + bString, true
		} else {
			bInt, bOk := b.Value().(int64)
			if bOk {
				return aString + strconv.FormatInt(bInt, 10), true
			}
		}
	}

	return "", false
}
開發者ID:vincentmisquez,項目名稱:spiff,代碼行數:16,代碼來源:concatenation.go


注:本文中的github.com/cloudfoundry-incubator/spiff/yaml.Node.Value方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。