-1

Please help to understand, how I can return from function not only values from structure but with their names?

Example my arg.go

package flags

import (
    "flag"
)

type FlagsStruct struct {
    argTest1  string
    argTest2   string
}

func GetInitFlags() *FlagsStruct {

    Flags := new(FlagsStruct)

    flag.StringVar(&Flags.argTest1, "test1", "test1", "c")
    flag.StringVar(&Flags.argTest2, "test2", "test2", "t")

    flag.Parse()

    return Flags

}

It's working only with keys, for example in my main function I trying to print and it's working:

fmt.Print(*inputFlags)

{test1 test2}

But how I can pass taht can print something like this?

fmt.Printf(inputFlags.argTest2)

./main.go:25:24: inputFlags.argTest2 undefined (cannot refer to unexported field or method argTest2)

Manish Iarhovich
  • 183
  • 1
  • 10
  • 3
    Does this answer your question? [Invoking struct function gives "cannot refer to unexported field or method"](https://stackoverflow.com/questions/24487943/invoking-struct-function-gives-cannot-refer-to-unexported-field-or-method) – Cameron Little Apr 19 '20 at 10:31

1 Answers1

1

Make your argument names start with a capital letter (ArgTest2). See this question for more details.

Cameron Little
  • 3,487
  • 23
  • 35