当前位置: 首页>>代码示例>>Golang>>正文


Golang DeepStack.PopDiscard方法代码示例

本文整理汇总了Golang中deepstack.DeepStack.PopDiscard方法的典型用法代码示例。如果您正苦于以下问题:Golang DeepStack.PopDiscard方法的具体用法?Golang DeepStack.PopDiscard怎么用?Golang DeepStack.PopDiscard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在deepstack.DeepStack的用法示例。


在下文中一共展示了DeepStack.PopDiscard方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: MakeFnWith

func MakeFnWith(sources *deepstack.DeepStack, outerRules *template.Rules) template.Rule {
	return func(path []interface{}, node interface{}) (interface{}, interface{}) {
		key := interface{}(nil)
		if len(path) > 0 {
			key = path[len(path)-1]
		}

		raw, ok := singleKey(node, "Fn::With")
		if !ok {
			return key, node //passthru
		}

		args, ok := collectArgs(
			raw,
			func(argsSoFar []interface{}) bool {
				return len(argsSoFar) < 2
			},
			func(argsSoFar []interface{}, arg interface{}) (bool, interface{}) {
				// unconditionally process the argument, in case it needs to be skipped
				key, node := template.Walk(path, arg, outerRules)
				if skip, ok := key.(bool); ok && skip {
					return true, nil
				}

				if len(argsSoFar) == 1 {
					return false, arg // return unprocessed 2nd arg. It's a template.
				}

				return false, node
			},
		)

		if !ok {
			return key, node //passthru
		}

		var source map[string]interface{}
		if source, ok = args[0].(map[string]interface{}); !ok {
			return key, node //passthru
		}

		sources.Push(fallbackmap.DeepMap(source))
		innerTemplate := interface{}(args[1])
		key, generated := template.Walk(path, innerTemplate, outerRules)
		sources.PopDiscard()

		return key, interface{}(generated)
	}
}
开发者ID:wpalmer,项目名称:condense,代码行数:49,代码来源:FnWith.go

示例2: MakeFnFor

func MakeFnFor(sources *deepstack.DeepStack, templateRules *template.Rules) template.Rule {
	return func(path []interface{}, node interface{}) (interface{}, interface{}) {
		key := interface{}(nil)
		if len(path) > 0 {
			key = path[len(path)-1]
		}

		raw, ok := singleKey(node, "Fn::For")
		if !ok {
			return key, node //passthru
		}

		args, ok := collectArgs(
			raw,
			func(argsSoFar []interface{}) bool { return len(argsSoFar) < 3 },
			func(argsSoFar []interface{}, arg interface{}) (skip bool, newNode interface{}) {
				// unconditionally process the argument, in case it needs to be skipped
				key, node := template.Walk(path, arg, templateRules)
				if skip, ok := key.(bool); ok && skip {
					return true, nil
				}

				if len(argsSoFar) == 2 {
					return false, arg // return unprocessed 3rd arg. It's a template.
				}

				return false, node
			},
		)
		if !ok {
			return key, node //passthru
		}

		var refNames []interface{}
		var refName interface{}

		if refNames, ok = args[0].([]interface{}); ok {
			if len(refNames) == 1 {
				refNames = []interface{}{nil, refNames[0]}
			} else if len(refNames) != 2 {
				return key, node //passthru
			}
		} else {
			refNames = []interface{}{nil, args[0]}
		}

		for _, refName = range refNames {
			if _, ok = refName.(string); !ok && refName != nil {
				return key, node //passthru
			}
		}

		valuesInterface := args[1]

		var values []interface{}
		if values, ok = valuesInterface.([]interface{}); !ok {
			return key, node //passthru
		}

		loopTemplate := interface{}(args[2])

		generated := []interface{}{}
		for deepIndex, value := range values {
			refMap := make(map[string]interface{})
			if refNames[0] != nil {
				refMap[refNames[0].(string)] = float64(deepIndex)
			}

			if refNames[1] != nil {
				refMap[refNames[1].(string)] = value
			}

			deepPath := make([]interface{}, len(path)+1)
			copy(deepPath, path)
			deepPath[cap(deepPath)-1] = interface{}(deepIndex)

			sources.Push(fallbackmap.DeepMap(refMap))

			newIndex, processed := template.Walk(deepPath, loopTemplate, templateRules)
			sources.PopDiscard()

			if newIndex != nil {
				generated = append(generated, processed)
			}
		}

		return key, interface{}(generated)
	}
}
开发者ID:wpalmer,项目名称:condense,代码行数:89,代码来源:FnFor.go

示例3: main


//.........这里部分代码省略.........
	templateRules.Attach(rules.FnMerge)
	templateRules.Attach(rules.FnMergeDeep)
	templateRules.Attach(rules.FnMod)
	templateRules.Attach(rules.FnSplit)
	templateRules.Attach(rules.FnToEntries)
	templateRules.Attach(rules.FnUnique)
	templateRules.Attach(rules.MakeFnGetAtt(&stack, &templateRules))
	templateRules.Attach(rules.MakeRef(&stack, &templateRules))
	templateRules.Attach(rules.MakeFnHasRef(&stack))
	templateRules.Attach(rules.MakeFnIncludeFile(vfs.OS("/"), &templateRules))
	templateRules.Attach(rules.MakeFnIncludeFileRaw(vfs.OS("/")))
	templateRules.Attach(rules.ReduceConditions)

	// First Pass (to collect Parameter names)
	processed := template.Process(t, &templateRules)

	parameterRefs := map[string]interface{}{}
	if processedMap, ok := processed.(map[string]interface{}); ok {
		if processedParameters, ok := processedMap["Parameters"]; ok {
			if processedParametersMap, ok := processedParameters.(map[string]interface{}); ok {
				for parameterName, _ := range processedParametersMap {
					parameterRefs[parameterName] = map[string]interface{}{
						"ParamRef": parameterName,
					}
				}
			}
		}
	}

	stack.Push(fallbackmap.DeepMap(parameterRefs))
	templateRules.Attach(func(path []interface{}, node interface{}) (interface{}, interface{}) {
		key := interface{}(nil)
		if len(path) > 0 {
			key = path[len(path)-1]
		}

		if nodeMap, ok := node.(map[string]interface{}); !ok || len(nodeMap) != 1 {
			return key, node //passthru
		}

		if refName, ok := node.(map[string]interface{})["ParamRef"]; ok {
			return key, interface{}(map[string]interface{}{"Ref": interface{}(refName)})
		}

		return key, node
	})
	processed = template.Process(t, &templateRules)
	stack.PopDiscard()

	switch outputWhat.Get().what {
	case OutputTemplate:
		enc := json.NewEncoder(os.Stdout)
		enc.Encode(processed)
	case OutputCredentials:
		credentials := []interface{}{}
		credentialMap := make(map[string]interface{})
		for _, input := range inputParameters.Sources() {
			if !outputWhat.Get().hasKey || outputWhat.Get().key == input.filename {
				credentialMap = template.Process(input.data, &templateRules).(map[string]interface{})
				credentialMap["$comment"] = map[string]interface{}{"filename": input.filename}
				credentials = append(credentials, credentialMap)
			}
		}

		if len(credentials) == 0 && outputWhat.Get().hasKey {
			panic(fmt.Errorf("No parameters file '%s' was input", outputWhat.Get().key))
		}

		enc := json.NewEncoder(os.Stdout)
		if len(credentials) == 1 {
			enc.Encode(credentials[0])
		} else {
			enc.Encode(credentials)
		}
	case OutputParameters:
		parameters := []cloudformation.Parameter{}

		for name, _ := range parameterRefs {
			value, ok := sources.Get([]string{name})
			if !ok {
				continue
			}

			value = template.Process(value, &templateRules)

			parameters = append(parameters, func(name string, value interface{}) cloudformation.Parameter {
				stringval := fmt.Sprintf("%s", value)
				boolval := false
				return cloudformation.Parameter{
					ParameterKey:     &name,
					ParameterValue:   &stringval,
					UsePreviousValue: &boolval,
				}
			}(name, value))
		}

		enc := json.NewEncoder(os.Stdout)
		enc.Encode(parameters)
	}
}
开发者ID:wpalmer,项目名称:condense,代码行数:101,代码来源:condense.go


注:本文中的deepstack.DeepStack.PopDiscard方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。