forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.go
69 lines (58 loc) · 1.86 KB
/
process.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package engine
import (
"path/filepath"
"github.com/yaoapp/gou"
"github.com/yaoapp/yao/config"
"github.com/yaoapp/yao/share"
"github.com/yaoapp/yao/xfs"
)
func init() {
// 注册处理器
gou.RegisterProcessHandler("xiang.main.Ping", processPing)
gou.AliasProcess("xiang.main.Ping", "xiang.sys.Ping")
gou.RegisterProcessHandler("xiang.main.FileContent", processFileContent)
gou.RegisterProcessHandler("xiang.main.AppFileContent", processAppFileContent)
gou.RegisterProcessHandler("xiang.main.Inspect", processInspect)
gou.AliasProcess("xiang.main.Inspect", "xiang.sys.Inspect")
gou.RegisterProcessHandler("xiang.main.Favicon", processFavicon)
}
// processCreate 运行模型 MustCreate
func processPing(process *gou.Process) interface{} {
res := map[string]interface{}{
"engine": share.BUILDNAME,
"version": share.VERSION,
}
return res
}
// processInspect 返回系统信息
func processInspect(process *gou.Process) interface{} {
share.App.Icons.Set("favicon", "/api/xiang/favicon.ico")
return share.App.Public()
}
// processFavicon 运行模型 MustCreate
func processFavicon(process *gou.Process) interface{} {
return xfs.DecodeString(share.App.Icons.Get("png").(string))
}
// processFileContent 返回文件内容
func processFileContent(process *gou.Process) interface{} {
process.ValidateArgNums(2)
filename := process.ArgsString(0)
encode := process.ArgsBool(1, true)
content := xfs.Stor.MustReadFile(filename)
if encode {
return xfs.Encode(content)
}
return string(content)
}
// processAppFileContent 返回应用文件内容
func processAppFileContent(process *gou.Process) interface{} {
process.ValidateArgNums(2)
fs := xfs.New(filepath.Join(config.Conf.Root, "data"))
filename := process.ArgsString(0)
encode := process.ArgsBool(1, true)
content := fs.MustReadFile(filename)
if encode {
return xfs.Encode(content)
}
return string(content)
}