本文整理汇总了Golang中github.com/hashicorp/otto/appfile.File.Merge方法的典型用法代码示例。如果您正苦于以下问题:Golang File.Merge方法的具体用法?Golang File.Merge怎么用?Golang File.Merge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/hashicorp/otto/appfile.File
的用法示例。
在下文中一共展示了File.Merge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Load
func (l *Loader) Load(f *appfile.File, dir string) (*appfile.File, error) {
realFile := f
// Load the "detected" Appfile
appDef, err := appfile.Default(dir, l.Detector)
if err != nil {
return nil, fmt.Errorf("Error detecting app type: %s", err)
}
// Merge the detected Appfile with the real Appfile
var merged appfile.File
if err := merged.Merge(appDef); err != nil {
return nil, fmt.Errorf("Error loading Appfile: %s", err)
}
if realFile != nil {
if err := merged.Merge(realFile); err != nil {
return nil, fmt.Errorf("Error loading Appfile: %s", err)
}
}
realFile = &merged
// If we have no application type, there is nothing more to do
if realFile == nil || realFile.Application.Type == "" {
return realFile, nil
}
// If we're not configured to do any further detection, return it
if !realFile.Application.Detect {
return realFile, nil
}
// Minimally compile the file that we can use to create a core
compiled, err := l.Compiler.MinCompile(realFile)
if err != nil {
return nil, err
}
// Create a temporary directory we use for the core
td, err := ioutil.TempDir("", "otto")
if err != nil {
return nil, err
}
defer os.RemoveAll(td)
// Create a core
core, err := otto.NewCore(&otto.CoreConfig{
DataDir: filepath.Join(td, "data"),
LocalDir: filepath.Join(td, "local"),
CompileDir: filepath.Join(td, "compile"),
Appfile: compiled,
Apps: l.Apps,
})
if err != nil {
return nil, err
}
// Get the app implementation
appImpl, appCtx, err := core.App()
if err != nil {
return nil, err
}
defer app.Close(appImpl)
// Load the implicit Appfile
implicit, err := appImpl.Implicit(appCtx)
if err != nil {
return nil, err
}
var final appfile.File
if err := final.Merge(appDef); err != nil {
return nil, fmt.Errorf("Error loading Appfile: %s", err)
}
if implicit != nil {
if err := final.Merge(implicit); err != nil {
return nil, fmt.Errorf("Error loading Appfile: %s", err)
}
}
if f != nil {
if err := final.Merge(f); err != nil {
return nil, fmt.Errorf("Error loading Appfile: %s", err)
}
}
return &final, nil
}