Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hhk7734/equeue.go
equeue.go is an Event Consumer, similar in usage to gin-gonic/gin
https://github.com/hhk7734/equeue.go
cloudevents framework gin golang middleware
Last synced: 1 day ago
JSON representation
equeue.go is an Event Consumer, similar in usage to gin-gonic/gin
- Host: GitHub
- URL: https://github.com/hhk7734/equeue.go
- Owner: hhk7734
- License: mit
- Created: 2023-07-02T17:21:47.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-16T12:57:20.000Z (6 months ago)
- Last Synced: 2024-05-17T12:46:44.397Z (6 months ago)
- Topics: cloudevents, framework, gin, golang, middleware
- Language: Go
- Homepage:
- Size: 60.5 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## equeue.go
### ZapxLoggerMiddleware
```go
package middlewareimport (
"fmt"
"runtime/debug"
"strconv"
"time""github.com/hhk7734/equeue.go"
"github.com/hhk7734/zapx.go"
"go.uber.org/zap"
)type ZapxLoggerMiddleware struct{}
func (z *ZapxLoggerMiddleware) Logger(c *equeue.Context) {
start := time.Now()
c.Next()ctx := zapx.WithFields(c.Request.Context(),
zap.String("ce_id", c.Request.Event.ID()),
zap.String("ce_type", c.Request.Event.Type()),
zap.String("ce_source", c.Request.Event.Source()),
zap.String("ce_time", c.Request.Event.Time().Format(time.RFC3339)),
zap.Duration("latency", time.Since(start)))
logger := zapx.Ctx(ctx)if len(c.Errors) > 0 {
for _, e := range c.Errors {
logger.Error("internal error", zap.Error(e))
}
} else {
logger.Info("logger")
}
}func (z *ZapxLoggerMiddleware) Recovery(c *equeue.Context) {
defer func() {
if err := recover(); err != nil {
c.AbortWithError(fmt.Errorf("%v\n%s", err, string(debug.Stack())))
}
}()
c.Next()
}
``````go
// r := equeue.New(...)
// ...zapxLogger := &middleware.ZapxLoggerMiddleware{}
r.Use(zapxLogger.Logger)
r.Use(zapxLogger.Recovery)
```