Skip to content

Commit

Permalink
Merge pull request #2 from DeBankDeFi/update
Browse files Browse the repository at this point in the history
chore: use glog lib finnaly
  • Loading branch information
barryz authored Dec 22, 2020
2 parents 4c94dd7 + 03eea58 commit dbddb81
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 56 deletions.
14 changes: 9 additions & 5 deletions amqp/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"strings"

"github.com/XSAM/go-hybrid/log"
log "github.com/DeBankDeFi/glog"
"github.com/streadway/amqp"
)

Expand All @@ -16,6 +16,10 @@ var (
ErrDeliveryChannelClosed = errors.New("delivery channel was closed")
)

var (
logger = log.NewLogFactory().DefaultLogger(log.LevelInfo)
)

// Config ...
type Config amqp.Config

Expand Down Expand Up @@ -113,21 +117,21 @@ type Handler func(ctx context.Context, ch *Channel, d *Delivery) error

// Consume consume message from amqp broker in block mode.
func (ch *Channel) Consume(ctx context.Context, queue string, handler Handler, dc <-chan amqp.Delivery) error {
log.BgLogger().Infof("amqp: start the consumer of %s queue", queue)
logger.Infof(ctx, "amqp: start the consumer of %s queue", queue)
for {
select {
case <-ctx.Done():
log.BgLogger().Infof("amqp: stop the consumer of %s queue", queue)
logger.Infof(ctx, "amqp: stop the consumer of %s queue", queue)
return nil
case d, ok := <-dc:
if !ok {
log.BgLogger().Warnf("amqp: the deliver channel of %s queue closed", queue)
logger.Warnf(ctx, "amqp: the deliver channel of %s queue closed", queue)
return ErrDeliveryChannelClosed
}
go func() {
err := ch.consume(queue, handler, &Delivery{&d})
if err != nil {
log.BgLogger().Warnf("amqp: execute handler with queue %s failed, reason: %v", queue, err.Error())
logger.Warnf(ctx, "amqp: execute handler with queue %s failed, reason: %v", queue, err.Error())
}
}()
}
Expand Down
8 changes: 4 additions & 4 deletions cmdhelper/version.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package cmdhelper

import (
"fmt"

"github.com/DeBankDeFi/golib/shared"

"github.com/XSAM/go-hybrid/log"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

func Version() *cobra.Command {
cmd := cobra.Command{
Use: "version",
Short: "Print version information",
Run: func(cmd *cobra.Command, args []string) {
log.BgLogger().Info("app info", zap.Any("info", shared.AppInfo()))
fmt.Println(shared.AppInfo())
},
}
return &cmd
}
}
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ module github.com/DeBankDeFi/golib
go 1.15

require (
github.com/XSAM/go-hybrid v1.0.0
github.com/DeBankDeFi/glog v0.0.0-20201123022541-666435a4b1f3
github.com/golang/protobuf v1.4.3
github.com/google/uuid v1.1.2
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.1.1
github.com/streadway/amqp v1.0.0
github.com/stretchr/testify v1.6.1
go.uber.org/zap v1.14.1
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // indirect
google.golang.org/grpc v1.33.2
)
Loading

0 comments on commit dbddb81

Please sign in to comment.