MCPcopy Create free account
hub / github.com/cloudwan/gohan / include

Function include

extension/gohanscript/stmtparser.go:86–114  ·  view source on GitHub ↗
(stmt *Stmt)

Source from the content-addressed store, hash-verified

84}
85
86func include(stmt *Stmt) (func(*Context) (interface{}, error), error) {
87
88 source := util.MaybeString(stmt.RawData["include"])
89 if !filepath.IsAbs(source) {
90 currentSource := stmt.File
91 source = filepath.Clean(filepath.Join(filepath.Dir(currentSource), source))
92 }
93 importedCode, err := LoadYAMLFile(source)
94 if err != nil {
95 return nil, stmt.Errorf("yaml parse error: %s", err)
96 }
97 stmt.Args = map[string]Value{}
98 for key, value := range stmt.RawData {
99 stmt.Args[key], err = NewValue(value)
100 if err != nil {
101 return nil, stmt.Errorf("yaml parse error: %s", err)
102 }
103 }
104 stmt.File = source
105 stmts, err := MakeStmts(stmt.File, importedCode)
106 if err != nil {
107 return nil, stmt.Errorf("import code parse error: %s", err)
108 }
109 stmt.Vars, err = MapToValue(util.MaybeMap(stmt.RawData["vars"]))
110 if err != nil {
111 return nil, stmt.Errorf("yaml parse error: %s", err)
112 }
113 return StmtsToFunc(stmt.funcName, stmts)
114}
115
116func background(stmt *Stmt) (func(*Context) (interface{}, error), error) {
117 stmts, err := MakeStmts(stmt.File, stmt.RawNode["background"])

Callers

nothing calls this directly

Calls 10

LoadYAMLFileFunction · 0.85
NewValueFunction · 0.85
MakeStmtsFunction · 0.85
MapToValueFunction · 0.85
StmtsToFuncFunction · 0.85
MaybeStringMethod · 0.80
JoinMethod · 0.80
DirMethod · 0.80
MaybeMapMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected