fix bug
This commit is contained in:
parent
5410f2e9d4
commit
9c4cf8a5ff
3 changed files with 42 additions and 5 deletions
|
|
@ -11,6 +11,7 @@ func init() {
|
||||||
gou.RegisterProcessHandler("xiang.global.FileContent", processFileContent)
|
gou.RegisterProcessHandler("xiang.global.FileContent", processFileContent)
|
||||||
gou.RegisterProcessHandler("xiang.global.AppFileContent", processAppFileContent)
|
gou.RegisterProcessHandler("xiang.global.AppFileContent", processAppFileContent)
|
||||||
gou.RegisterProcessHandler("xiang.global.Inspect", processInspect)
|
gou.RegisterProcessHandler("xiang.global.Inspect", processInspect)
|
||||||
|
gou.RegisterProcessHandler("xiang.global.Favicon", processFavicon)
|
||||||
}
|
}
|
||||||
|
|
||||||
// processCreate 运行模型 MustCreate
|
// processCreate 运行模型 MustCreate
|
||||||
|
|
@ -25,11 +26,17 @@ func processPing(process *gou.Process) interface{} {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// processCreate 运行模型 MustCreate
|
// processInspect 返回系统信息
|
||||||
func processInspect(process *gou.Process) interface{} {
|
func processInspect(process *gou.Process) interface{} {
|
||||||
|
App.Icons["favicon"] = "/api/xiang/favicon.ico"
|
||||||
return App
|
return App
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// processFavicon 运行模型 MustCreate
|
||||||
|
func processFavicon(process *gou.Process) interface{} {
|
||||||
|
return xfs.DecodeString(App.Icons["png"])
|
||||||
|
}
|
||||||
|
|
||||||
// processFileContent 返回文件内容
|
// processFileContent 返回文件内容
|
||||||
func processFileContent(process *gou.Process) interface{} {
|
func processFileContent(process *gou.Process) interface{} {
|
||||||
process.ValidateArgNums(2)
|
process.ValidateArgNums(2)
|
||||||
|
|
|
||||||
27
xfs/xfs.go
27
xfs/xfs.go
|
|
@ -66,10 +66,10 @@ func New(path string) Xfs {
|
||||||
exception.New("尚未支持 %s 文件系统", 500, fs).Throw()
|
exception.New("尚未支持 %s 文件系统", 500, fs).Throw()
|
||||||
}
|
}
|
||||||
|
|
||||||
exists := xfs.MustDirExists("/")
|
// exists := xfs.MustDirExists("/")
|
||||||
if !exists {
|
// if !exists && root != "/" {
|
||||||
xfs.MustMkdirAll("/", os.ModePerm)
|
// xfs.MustMkdirAll("/", os.ModePerm)
|
||||||
}
|
// }
|
||||||
|
|
||||||
return xfs
|
return xfs
|
||||||
}
|
}
|
||||||
|
|
@ -105,6 +105,25 @@ func Encode(content []byte) string {
|
||||||
return base64.StdEncoding.EncodeToString(content)
|
return base64.StdEncoding.EncodeToString(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decode Base64编码
|
||||||
|
func Decode(content []byte) []byte {
|
||||||
|
var data []byte
|
||||||
|
_, err := base64.StdEncoding.Decode(data, content)
|
||||||
|
if err != nil {
|
||||||
|
exception.New("文件解码失败 %s ", 500, err).Throw()
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecodeString Base64编码
|
||||||
|
func DecodeString(content string) string {
|
||||||
|
dst, err := base64.StdEncoding.DecodeString(content)
|
||||||
|
if err != nil {
|
||||||
|
exception.New("文件解码失败 %s ", 500, err).Throw()
|
||||||
|
}
|
||||||
|
return string(dst)
|
||||||
|
}
|
||||||
|
|
||||||
// MustOpen 打开文件
|
// MustOpen 打开文件
|
||||||
func (xfs *Xfs) MustOpen(filename string) File {
|
func (xfs *Xfs) MustOpen(filename string) File {
|
||||||
file, err := xfs.Open(filename)
|
file, err := xfs.Open(filename)
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,17 @@
|
||||||
"status": 200,
|
"status": 200,
|
||||||
"type": "application/json"
|
"type": "application/json"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"path": "/favicon.ico",
|
||||||
|
"method": "GET",
|
||||||
|
"guard": "-",
|
||||||
|
"process": "xiang.global.Favicon",
|
||||||
|
"in": [],
|
||||||
|
"out": {
|
||||||
|
"status": 200,
|
||||||
|
"type": "image/x-icon"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue