[add] Table API delete Hooks
This commit is contained in:
parent
687a477134
commit
0089036af2
4 changed files with 12 additions and 6 deletions
1
go.mod
1
go.mod
|
|
@ -28,7 +28,6 @@ require (
|
|||
github.com/json-iterator/go v1.1.12
|
||||
github.com/lib/pq v1.10.4 // indirect
|
||||
github.com/mattn/go-sqlite3 v1.14.9 // indirect
|
||||
github.com/miekg/dns v1.1.48 // indirect
|
||||
github.com/mojocn/base64Captcha v1.3.5
|
||||
github.com/satori/go.uuid v1.2.0 // indirect
|
||||
github.com/spf13/afero v1.6.0
|
||||
|
|
|
|||
3
go.sum
3
go.sum
|
|
@ -350,8 +350,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
|
|||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
|
||||
github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
|
||||
github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg=
|
||||
github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4=
|
||||
github.com/miekg/dns v1.1.48 h1:Ucfr7IIVyMBz4lRE8qmGUuZ4Wt3/ZGu9hmcMT3Uu4tQ=
|
||||
github.com/miekg/dns v1.1.48/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
|
||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||
|
|
@ -675,7 +673,6 @@ golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
|
|
|||
|
|
@ -129,11 +129,17 @@ func ProcessDelete(process *gou.Process) interface{} {
|
|||
table := Select(name)
|
||||
api := table.APIs["delete"].ValidateLoop("xiang.table.delete")
|
||||
|
||||
// Before Hook
|
||||
process.Args = table.Before(table.Hooks.BeforeDelete, process.Args, process.Sid)
|
||||
|
||||
id := process.Args[1]
|
||||
return gou.NewProcess(api.Process, id).
|
||||
response := gou.NewProcess(api.Process, id).
|
||||
WithGlobal(process.Global).
|
||||
WithSID(process.Sid).
|
||||
Run()
|
||||
|
||||
// After Hook
|
||||
return table.After(table.Hooks.AfterDelete, response, []interface{}{id}, process.Sid)
|
||||
}
|
||||
|
||||
// ProcessDeleteWhere xiang.table.DeleteWhere
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ func Guard(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
log.Trace("Table Guard FullPath: %s", c.FullPath())
|
||||
|
||||
routes := strings.Split(c.FullPath(), "/")
|
||||
path := routes[len(routes)-1]
|
||||
name, has := c.Params.Get("name")
|
||||
|
|
@ -52,6 +54,8 @@ func Guard(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
log.Trace("Table Guard: %s %s %s", name, api.Guard, path)
|
||||
|
||||
if api.Guard == "-" {
|
||||
c.Next()
|
||||
return
|
||||
|
|
@ -64,7 +68,7 @@ func Guard(c *gin.Context) {
|
|||
guards := strings.Split(api.Guard, ",")
|
||||
for _, guard := range guards {
|
||||
guard = strings.TrimSpace(guard)
|
||||
log.Trace("Guard Table %s %s", name, guard)
|
||||
log.Trace("Table Guard: %s %s", name, guard)
|
||||
if guard != "" {
|
||||
if middleware, has := gou.HTTPGuards[guard]; has {
|
||||
middleware(c)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue