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

Marshal and unmarshal functions #337

Open
1 task done
iFrozenPhoenix opened this issue Mar 4, 2023 · 0 comments
Open
1 task done

Marshal and unmarshal functions #337

iFrozenPhoenix opened this issue Mar 4, 2023 · 0 comments
Labels
feature Categorizes as related to a new feature

Comments

@iFrozenPhoenix
Copy link

Describe the feature

Usage of this module feels strange compared to other encoding formats like json or yaml.
These modules provide functions that can be used to directly marshal structs/maps into []byte and unmarhsal from []byte into
a struct/map.

Describe the solution you'd like

A way to marshal/unmarshal the same way as in other encoding modules.

package ini

func Marshal(v any) ([]byte, error) {
	e := Empty()
	err := e.ReflectFrom(v)
	if err != nil {
		return nil, err
	}

	buf, err := e.writeToBuffer("")
	if err != nil {
		return nil, err
	}

	return buf.Bytes(), nil
}

func Unmarshal(data []byte, v any) error {
	ini, err := Load(data)
	if err != nil {
		return err
	}

	err = ini.MapTo(v)
	if err != nil {
		return err
	}

	return nil
}

Describe alternatives you've considered

Using an internal fork of this module

Additional context

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@iFrozenPhoenix iFrozenPhoenix added the feature Categorizes as related to a new feature label Mar 4, 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