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


Golang Rules.AttachEarly方法代码示例

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


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

示例1: main

func main() {
	templateRules := template.Rules{}
	inputParameters := NewInputsFlag(&templateRules)
	var templateFilename string
	var outputWhat OutputWhatFlag

	flag.StringVar(&templateFilename,
		"template", "-",
		"CloudFormation Template to process")

	flag.Var(&inputParameters,
		"parameters",
		"File to use of input parameters (can be specified multiple times)")

	flag.Var(&outputWhat,
		"output",
		"What to output after processing the Template")

	flag.Parse()

	var jsonStream io.Reader
	var err error

	if templateFilename == "-" {
		jsonStream = os.Stdin
	} else if jsonStream, err = os.Open(templateFilename); err != nil {
		panic(err)
	}

	dec := json.NewDecoder(jsonStream)
	t := make(map[string]interface{})
	if err := dec.Decode(&t); err != nil {
		panic(err)
	}

	sources := fallbackmap.FallbackMap{}
	stack := deepstack.DeepStack{}

	sources.Attach(inputParameters.Get())
	sources.Attach(deepalias.DeepAlias{&stack})
	sources.Attach(deepcloudformationoutputs.NewDeepCloudFormationOutputs("eu-west-1"))
	sources.Attach(deepcloudformationresources.NewDeepCloudFormationResources("eu-west-1"))

	stack.Push(&sources)

	templateRules.AttachEarly(rules.ExcludeComments)
	templateRules.AttachEarly(rules.MakeFnFor(&stack, &templateRules))
	templateRules.AttachEarly(rules.MakeFnWith(&stack, &templateRules))
	templateRules.Attach(rules.FnAdd)
	templateRules.Attach(rules.FnIf)
	templateRules.Attach(rules.FnAnd)
	templateRules.Attach(rules.FnOr)
	templateRules.Attach(rules.FnNot)
	templateRules.Attach(rules.FnEquals)
	templateRules.Attach(rules.FnConcat)
	templateRules.Attach(rules.FnFromEntries)
	templateRules.Attach(rules.FnHasKey)
	templateRules.Attach(rules.FnJoin)
	templateRules.Attach(rules.FnKeys)
	templateRules.Attach(rules.FnLength)
	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
		}

//.........这里部分代码省略.........
开发者ID:wpalmer,项目名称:condense,代码行数:101,代码来源:condense.go


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