servicecontext.go 577 B

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