本文整理汇总了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
}
//.........这里部分代码省略.........