From 0089036af2514b808be4dc8bff984305bd5ec939 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 7 May 2022 08:20:48 +0800 Subject: [PATCH] [add] Table API delete Hooks --- go.mod | 1 - go.sum | 3 --- table/process.go | 8 +++++++- table/table.go | 6 +++++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 96636915..96fa511b 100644 --- a/go.mod +++ b/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 diff --git a/go.sum b/go.sum index 270b0319..855e8cec 100644 --- a/go.sum +++ b/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= diff --git a/table/process.go b/table/process.go index a6154d5e..279a8a74 100644 --- a/table/process.go +++ b/table/process.go @@ -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 diff --git a/table/table.go b/table/table.go index a652892c..b5c4fce9 100644 --- a/table/table.go +++ b/table/table.go @@ -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)