Get a config file from a json or CLI

hi i wrote this code to get parameters from the CLI, but I would like to modify it to make possible also to get those parameters from a json.

type Options struct {
	one *string
	two  *string
	three *string

func ParseOptions() (Options) {
	opt := Options {
		one : flag.String(...),
		two : flag.String(....),
		three : flag.String(...),


	return opt

how can I make it, should i first ask for example to enter 1 if take in input things from cli and 2 from a json? the how should i decode/parse the json?

What do you mean by “from a JSON”? Do you parse a JSON file? Then you should give the path to this file as a flag.String, read the file and parse it.

1 Like

i men that i run my go run main.go -configuration.json and it stores all the configuration inside that file, in the variables one two three

Which part of this is the name of the JSON file? Is the file named configuration.json? If yes, do as I suggested above.

1 Like

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