Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More of a question setDecoder manually #139

Closed
meetme2meat opened this issue Apr 11, 2023 · 3 comments
Closed

More of a question setDecoder manually #139

meetme2meat opened this issue Apr 11, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request question Further information is requested resolved

Comments

@meetme2meat
Copy link

we have our legacy system where I would want to replace our existing config manager with the gookit the problem I'm facing straight up with integration is past developers have used .conf for ini file.

In my attempt to let gookit/config to consider .conf to consider as an INI decoder I stumble

config.SetDecoder("conf", ini.Driver.GetDecoder())

All works well but the API seem to be deprecated and I'm not sure how to ensure that how this can be done with the latest API

        config.SetDecoder("conf", ini.Driver.GetDecoder())
	config.AddDriver(ini.Driver)
	config.WithOptions(
		config.ParseEnv,
		config.WithHookFunc(func(event string, c *config.Config) {
			if event == config.OnReloadData {
				zap.L().Info("config is reloaded")
			}
		}),
	)

	err := config.LoadFiles(
		constants.CONFIG_INI,
		constants.SUGARBOX_INI,
	)

	if err != nil {
		panic(err)
	}

	go watchConfigFiles(config.Default())

Let me know anything that can be done here that not deprecated.

@inhere
Copy link
Member

inhere commented Apr 11, 2023

refer the ini/ini.go

// make Driver for conf format.
var confDriver = config.NewDriver('conf', ini.Decoder, ini.Encoder)

config.AddDriver(ini.Driver)
config.AddDriver(confDriver)

@inhere inhere added the question Further information is requested label Apr 11, 2023
@meetme2meat
Copy link
Author

meetme2meat commented Apr 11, 2023

@inhere Nope I already tried that, getting the following error

panic: not register decoder for the format: hcl


this work though.


confDriver := config.NewDriver("hcl", ini.Decoder, ini.Encoder)

This begs me a question should AddDriver also should perform a lookup with the fixFormat first and then set the decoder and encoder?

@inhere inhere added the enhancement New feature or request label May 8, 2023
@inhere
Copy link
Member

inhere commented Jun 11, 2023

Hi @meetme2meat

add new method for support driver name alias:

// https://github.com/gookit/config/issues/139
func TestIssues_139(t *testing.T) {
	c := config.New("issues_139", config.ParseEnv)
	c.AddDriver(ini.Driver)
	c.AddAlias("ini", "conf") // <<<<- add format alias

	err := c.LoadFiles("testdata/issues_139.conf") // will parse use ini format.
	assert.NoErr(t, err)

	assert.Eq(t, "app", c.String("name"))
	assert.Eq(t, "defValue", c.String("envKey1"))
}

The feature will release on next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested resolved
Projects
None yet
Development

No branches or pull requests

2 participants