servicecontext.go 744 B

12345678910111213141516171819202122232425262728
  1. package svc
  2. import (
  3. "github.com/zeromicro/go-zero/core/stores/redis"
  4. "github.com/zeromicro/go-zero/zrpc"
  5. "ylink/core/cmd/rpc/internal/config"
  6. "ylink/core/inner/rpc/inner"
  7. "ylink/ext/kafka"
  8. )
  9. type ServiceContext struct {
  10. Config config.Config
  11. InnerRpc inner.Inner
  12. SendBoxProducer *kafka.Producer
  13. RedisClient *redis.Redis
  14. }
  15. func NewServiceContext(c config.Config) *ServiceContext {
  16. return &ServiceContext{
  17. Config: c,
  18. InnerRpc: inner.NewInner(zrpc.MustNewClient(c.InnerRpcConf)),
  19. SendBoxProducer: kafka.NewKafkaProducer(c.KqSendMsgConf.Brokers, c.KqSendMsgConf.Topic),
  20. RedisClient: redis.New(c.Redis.Host, func(r *redis.Redis) {
  21. r.Type = c.Redis.Type
  22. r.Pass = c.Redis.Pass
  23. }),
  24. }
  25. }