go-zero: Unable to set default values in config

I am unable to set default value to config

etc/config.yaml

Media:
 
  MediaImageMaxSize: ${MEDIA_IMAGE_MAX_SIZE}

  MediaVideoMaxSize: ${MEDIA_VIDEO_MAX_SIZE}

  MediaDescriptionMaxLength: ${MEDIA_DESCRIPTION_MAX_LENGTH}

  MediaVideoTitleMaxLength: ${MEDIA_TITLE_MAX_LENGTH}

config.go

Media struct {
        MediaImageMaxSize         int64 `json:",default=5242880"`
        MediaVideoMaxSize         int64 `json:",default=41943040"`
        MediaDescriptionMaxLength int64 `json:",default=150"`
        MediaVideoTitleMaxLength  int64 `json:",default=25"`
    }

But I am getting this error

2022/08/15 23:17:28 error: config file etc/config.yaml, error: type mismatch for field Media.MediaImageMaxSize
exit status 1

also vscode shows warning as shown in the image. I think values from default tag are not being read. Any idea?

image

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (12 by maintainers)

Most upvoted comments

@kevwan currently if want to read a value from env we have to first specify it in etc/config.yml.

I think it would be better if we provide the default values in the etc/config.yml. To override an env var we could just pass an env var through env file.

if the configuration in config.yml is like this

Media:
	ImageSize: 24444

then gozero should expect MEDIA_IMAGE_SIZE as an env var.