forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.go
49 lines (40 loc) · 1001 Bytes
/
script.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package script
import (
"fmt"
"path/filepath"
"github.com/yaoapp/gou"
"github.com/yaoapp/kun/log"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/share"
)
// Load 加载共享库
func Load(cfg config.Config) error {
if share.BUILDIN {
return LoadBuildIn("scripts")
}
err := LoadFrom(filepath.Join(cfg.Root, "scripts"), "")
if err != nil {
return err
}
return LoadFrom(filepath.Join(cfg.Root, "services"), "__yao_service.")
}
// LoadBuildIn 从制品中读取
func LoadBuildIn(dir string) error {
return nil
}
// LoadFrom 从特定目录加载共享库
func LoadFrom(dir string, prefix string) error {
if share.DirNotExists(dir) {
log.Error("%s does not exists", dir)
return nil
}
// 加载共享脚本
err := share.Walk(dir, ".js", func(root, filename string) {
name := share.SpecName(root, filename)
err := gou.Yao.Load(filename, fmt.Sprintf("%s%s", prefix, name))
if err != nil {
log.Error("加载脚本失败 %s", err.Error())
}
})
return err
}