Ini file output

Hi,

I would like to write an application config in go using flags and then have it output into an .ini file.

I’ve done this with JSON files, but can’t figure out the ini.

Any suggestions?

Ini file will look like so:

Name=*flag input

[Output]
Mode=*flag input

[Input]
BaseCX=*flag input
BaseCY=*flag input
Common=*flag input

Thanks!

What is the code you use that produces this output?

Its for a 3rd party application. It reads just the ini file.

No, what code do you use to write the INI file? Is the snippet you pasted above some output your code produces?

That’s the output I need to achieve.

The issue is, no sure where to start and can’t figure out the https://github.com/go-ini/ini package.

I’ve never used this package before but it looks easy. This Go code

package main

import (
	"github.com/go-ini/ini"
)

func main() {
	cfg := ini.Empty()

	sctInput := cfg.Section("Input")
	sctInput.NewKey("Common", "common")

	cfg.SaveTo("/tmp/foo.ini")
}

writes this

[Input]
Common = common

to /tmp/foo.ini.

It should be easy to write the flag values.

1 Like

Awesome, thank! Works!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.