#Cannot use 'values' (type []string) as the type []any

7 messages · Page 1 of 1 (latest)

magic galleon
#
func Open(gormConfig gorm.Config) (db *gorm.DB, err error) {
    // get database route information through environment variables
    var values []string
    values, err = config.ReadMany("DB_HOST", "DB_USER", "DB_PASSWORD", "DB_NAME")

    // get dsn
    dsn := fmt.Sprintf("host=%w user=%w password=%w dbname=%w", values...) // <- COMPILE ERROR HERE 

    // open database
    return gorm.Open(postgres.Open(dsn), &gormConfig)
}

I'm getting a compile error at values..., its giving me "Cannot use 'values' (type []string) as the type []any".

Is there any way to work around to this, can I convert var values []string to var values []any or the other way around?"

Thanks

elder hamlet
#

The only way is to loop

magic galleon
#

and convert to string?

elder hamlet
#

Convert to []any

magic galleon
#

oh yeah

#

hmm ok thx

oblique estuary
#

I think you could make it even simpler