MCPcopy
hub / github.com/marmotedu/iam / Publish

Function Publish

internal/pkg/middleware/publish.go:21–48  ·  view source on GitHub ↗

Publish publish a redis event to specified redis channel when some action occurred.

()

Source from the content-addressed store, hash-verified

19
20// Publish publish a redis event to specified redis channel when some action occurred.
21func Publish() gin.HandlerFunc {
22 return func(c *gin.Context) {
23 c.Next()
24
25 if c.Writer.Status() != http.StatusOK {
26 log.L(c).Debugf("request failed with http status code `%d`, ignore publish message", c.Writer.Status())
27
28 return
29 }
30
31 var resource string
32
33 pathSplit := strings.Split(c.Request.URL.Path, "/")
34 if len(pathSplit) > 2 {
35 resource = pathSplit[2]
36 }
37
38 method := c.Request.Method
39
40 switch resource {
41 case "policies":
42 notify(c, method, load.NoticePolicyChanged)
43 case "secrets":
44 notify(c, method, load.NoticeSecretChanged)
45 default:
46 }
47 }
48}
49
50func notify(ctx context.Context, method string, command load.NotificationCommand) {
51 switch method {

Callers 1

installControllerFunction · 0.92

Calls 4

LFunction · 0.92
notifyFunction · 0.85
NextMethod · 0.80
DebugfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…