Skip to content

Can't load config into struct with json tags #85

Description

@slon

I noticed a regression in behaviour. Here is code for reproducing the issue.

package confitajson

import (
	"context"
	"log"
	"testing"

	"github.com/heetch/confita"
	"github.com/heetch/confita/backend/file"
)

func TestLoad(t *testing.T) {
	b := file.NewBackend("config.json")

	var c struct {
		Field string `json:"field"`
	}

	if err := confita.NewLoader(b).Load(context.Background(), &c); err != nil {
		log.Fatalf("failed to load config: %v", err)
	}

	if c.Field != "value" {
		log.Fatal("field value is not updated")
	}
}

Content of config.json file is following:

{
    "field": "value"
}

When running this test on the latest confita release, struct field is not updated. But on version v0.7.0 code works fine.

prime@bee ~/C/confitajson> go get github.com/heetch/confita@v0.7.0
go: downloading github.com/heetch/confita v0.7.0
prime@bee ~/C/confitajson> go test .
ok  	github.com/slon/confitajson	0.002s
prime@bee ~/C/confitajson> go get github.com/heetch/confita
go: github.com/heetch/confita upgrade => v0.9.1
prime@bee ~/C/confitajson> go test .
2020/05/27 20:02:34 field value is not updated
FAIL	github.com/slon/confitajson	0.002s
FAIL

I also noticed, that removing these 3 lines, seems to fix this issue for me. https://github.com/heetch/confita/blob/master/config.go#L183-L185

Is that change in behaviour intentional, or is it indeed a regression?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions