afterhook with payload

This commit is contained in:
Max 2022-01-26 11:28:33 +08:00
parent cb49dc3654
commit b9e8f972ce
2 changed files with 11 additions and 10 deletions

View file

@ -59,7 +59,7 @@ func ProcessSearch(process *gou.Process) interface{} {
response := gou.NewProcess(api.Process, param, page, pagesize).Run() response := gou.NewProcess(api.Process, param, page, pagesize).Run()
// After Hook // After Hook
return table.After(table.Hooks.AfterSearch, response, process.Sid) return table.After(table.Hooks.AfterSearch, response, []interface{}{param, page, pagesize}, process.Sid)
} }
// ProcessFind xiang.table.Find // ProcessFind xiang.table.Find
@ -86,7 +86,7 @@ func ProcessFind(process *gou.Process) interface{} {
response := gou.NewProcess(api.Process, id, param).Run() response := gou.NewProcess(api.Process, id, param).Run()
// After Hook // After Hook
return table.After(table.Hooks.AfterFind, response, process.Sid) return table.After(table.Hooks.AfterFind, response, []interface{}{id, param}, process.Sid)
} }
// ProcessSave xiang.table.Save // ProcessSave xiang.table.Save
@ -98,9 +98,9 @@ func ProcessSave(process *gou.Process) interface{} {
name := process.ArgsString(0) name := process.ArgsString(0)
table := Select(name) table := Select(name)
api := table.APIs["save"].ValidateLoop("xiang.table.save") api := table.APIs["save"].ValidateLoop("xiang.table.save")
if process.NumOfArgsIs(3) && api.IsAllow(process.Args[2]) { // if process.NumOfArgsIs(3) && api.IsAllow(process.Args[2]) {
return nil // return nil
} // }
// Before Hook // Before Hook
process.Args = table.Before(table.Hooks.BeforeSave, process.Args, process.Sid) process.Args = table.Before(table.Hooks.BeforeSave, process.Args, process.Sid)
@ -112,7 +112,7 @@ func ProcessSave(process *gou.Process) interface{} {
response := gou.NewProcess(api.Process, process.Args[1]).Run() response := gou.NewProcess(api.Process, process.Args[1]).Run()
// After Hook // After Hook
return table.After(table.Hooks.AfterSave, response, process.Sid) return table.After(table.Hooks.AfterSave, response, []interface{}{process.Args[1]}, process.Sid)
} }
// ProcessDelete xiang.table.Delete // ProcessDelete xiang.table.Delete
@ -328,5 +328,5 @@ func ProcessSelect(process *gou.Process) interface{} {
response := gou.NewProcess(api.Process, process.Args[1:]...).Run() response := gou.NewProcess(api.Process, process.Args[1:]...).Run()
// After Hook // After Hook
return table.After(table.Hooks.AfterSelect, response, process.Sid) return table.After(table.Hooks.AfterSelect, response, process.Args[1:], process.Sid)
} }

View file

@ -177,13 +177,14 @@ func (table *Table) Before(process string, processArgs []interface{}, sid string
} }
// After 运行 After hook // After 运行 After hook
func (table *Table) After(process string, data interface{}, sid string) interface{} { func (table *Table) After(process string, data interface{}, args []interface{}, sid string) interface{} {
if process == "" { if process == "" {
return data return data
} }
response, err := gou.NewProcess(process, data).WithSID(sid).Exec() args = append([]interface{}{data}, args...)
response, err := gou.NewProcess(process, args...).WithSID(sid).Exec()
if err != nil { if err != nil {
xlog.Println("Hook执行失败: ", err.Error(), maps.StrAny{"process": process, "data": data}) xlog.Println("Hook执行失败: ", err.Error(), maps.StrAny{"process": process, "args": args})
return data return data
} }
return response return response