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

key prefixes #333

Open
1 task done
kpramesh2212 opened this issue Jan 12, 2023 · 0 comments
Open
1 task done

key prefixes #333

kpramesh2212 opened this issue Jan 12, 2023 · 0 comments
Labels
feature Categorizes as related to a new feature

Comments

@kpramesh2212
Copy link

kpramesh2212 commented Jan 12, 2023

Describe the feature

I have the following code


import "gopkg.in/ini.v1"

type AccessKey struct {
	AccessKeyId     string `ini:"access_key_id"`
	AccessKeySecret string `ini:"access_key_secret"`
}

type User struct {
	Root    AccessKey `ini:"User"`
	Default AccessKey `ini:"User"`
	Name    string    `ini:"name"`
}

type Section struct {
	User User
}

func main() {
	cfg, err := ini.Load("credential")
	if err != nil {
		panic(err)
	}

	s1 := Section{
		User: User{
			Root: AccessKey{
				AccessKeyId:     "privkey",
				AccessKeySecret: "privsecret",
			},
			Default: AccessKey{
				AccessKeyId:     "key1",
				AccessKeySecret: "secret1",
			},
			Name: "Ramesh",
		},
	}

	if err = cfg.ReflectFrom(&s1); err != nil {
		panic(err)
	}

	if err = cfg.SaveTo("user.ini"); err != nil {
		panic(err)
	}
}

Which produces the following output

[User]
access_key_id     = key1
access_key_secret = secret1
name              = Ramesh

Describe the solution you'd like

Is it possible to add functionality such that

if a prefix is attached to a struct type then all keys of the struct type would have the prefix

type User struct {
	Root    AccessKey `ini:"User" prefix:"root"`
	Default AccessKey `ini:"User" prefix:""`
	Name    string    `ini:"name"`
}

So that the output look like this

[User]
access_key_id     = key1
access_key_secret = secret1
root_access_key_id     = privkey
root_access_key_secret = privsecret
name              = Ramesh

Describe alternatives you've considered

I have none if you could suggest one that might work it will be great.

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@kpramesh2212 kpramesh2212 added the feature Categorizes as related to a new feature label Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Categorizes as related to a new feature
Projects
None yet
Development

No branches or pull requests

1 participant