123456789101112131415161718192021222324252627282930313233343536373839 |
- package middleware
- import (
- "git.sxidc.com/go-tools/api_binding/mqtt_binding/mqtt_client/router"
- "git.sxidc.com/service-supports/fslog"
- "runtime/debug"
- "slices"
- "time"
- )
- func Logger(skipTopics []string) router.Handler {
- return func(item *router.Item, data []byte) {
- start := time.Now()
- item.Next()
- if slices.Contains(skipTopics, item.Topic) {
- return
- }
- end := time.Now()
- fslog.Info("| %d | %s |",
- end.Sub(start),
- item.Topic,
- )
- }
- }
- func Recovery() router.Handler {
- return func(item *router.Item, data []byte) {
- defer func() {
- err := recover()
- if err != nil {
- fslog.Error("%s", debug.Stack())
- }
- }()
- item.Next()
- }
- }
|