github.com/goravel/framework@v1.13.9/queue/config.go (about) 1 package queue 2 3 import ( 4 "fmt" 5 6 configcontract "github.com/goravel/framework/contracts/config" 7 ) 8 9 type Config struct { 10 config configcontract.Config 11 } 12 13 func NewConfig(config configcontract.Config) *Config { 14 return &Config{ 15 config: config, 16 } 17 } 18 19 func (r *Config) DefaultConnection() string { 20 return r.config.GetString("queue.default") 21 } 22 23 func (r *Config) Queue(connection, queue string) string { 24 appName := r.config.GetString("app.name") 25 if appName == "" { 26 appName = "goravel" 27 } 28 if connection == "" { 29 connection = r.DefaultConnection() 30 } 31 if queue == "" { 32 queue = r.config.GetString(fmt.Sprintf("queue.connections.%s.queue", connection), "default") 33 } 34 35 return fmt.Sprintf("%s_%s:%s", appName, "queues", queue) 36 } 37 38 func (r *Config) Driver(connection string) string { 39 if connection == "" { 40 connection = r.config.GetString("queue.default") 41 } 42 43 return r.config.GetString(fmt.Sprintf("queue.connections.%s.driver", connection)) 44 } 45 46 func (r *Config) Redis(queueConnection string) (dsn string, database int, queue string) { 47 connection := r.config.GetString(fmt.Sprintf("queue.connections.%s.connection", queueConnection)) 48 queue = r.Queue(queueConnection, "") 49 host := r.config.GetString(fmt.Sprintf("database.redis.%s.host", connection)) 50 password := r.config.GetString(fmt.Sprintf("database.redis.%s.password", connection)) 51 port := r.config.GetInt(fmt.Sprintf("database.redis.%s.port", connection)) 52 database = r.config.GetInt(fmt.Sprintf("database.redis.%s.database", connection)) 53 54 if password == "" { 55 dsn = fmt.Sprintf("%s:%d", host, port) 56 } else { 57 dsn = fmt.Sprintf("%s@%s:%d", password, host, port) 58 } 59 60 return 61 }