Skip to content

[BUG] Config parsing with type conversion and env var replacement mangles input #3638

@th3fallen

Description

@th3fallen

with this config.yaml

server:
  http:
    addr: 0.0.0.0:8000
    timeout: 100s
  grpc:
    addr: 0.0.0.0:9000
    timeout: 100s
data:
  database:
    driver: mysql
    source: ${DB_USERNAME:root}:${DB_PASSWORD:password}@tcp(${DB_HOST:mysql.default.svc.cluster.local:3306})/${DB_NAME:remoteconfig}?parseTime=True&loc=Local
    debug: ${DB_DEBUG:false}

and this config options

c := config.New(
		config.WithResolveActualTypes(true),
		config.WithSource(
			file.NewSource(flagconf),
			env.NewSource(),
		),
	)

What happened:

With the above inputs, when i enable WithResolveActualTypes the value returned from data.database.source is root

What you expected to happen:

data.database.source should return root:password@tcp(mysql.default.svc.cluster.local:3306)/remoteconfig?parseTime=True&loc=Local

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

The error appears to stem from https://github.com/go-kratos/kratos/blob/main/config/options.go#L189

Environment:

  • Kratos version (use kratos -v): kratos version v2.8.4
  • Go version (use go version):go version go1.24.2 darwin/arm64
  • OS (e.g: cat /etc/os-release):OSX Latest

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions