本文整理匯總了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
}
//.........這裏部分代碼省略.........