Publish publish a redis event to specified redis channel when some action occurred.
()
| 19 | |
| 20 | // Publish publish a redis event to specified redis channel when some action occurred. |
| 21 | func 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 | |
| 50 | func notify(ctx context.Context, method string, command load.NotificationCommand) { |
| 51 | switch method { |
no test coverage detected
searching dependent graphs…