I created a simple program where I set 2 flags and build it. How to read these flags and set this 2 values from compiled binary?
I tried to read the file many ways but I did not find the flag value.
flag.go
var (
name *string
version *int
)
func init(){
name = flag.String("name","test", "a string")
version = flag.Int("version", 1.0, "an int")
}
func main(){
flag.Parse()
fmt.Println("name : ", *name)
fmt.Println("version : ", *version)
}
main.go
func main(){
path := "/Users/____/Desktop/flag"
dat,_ := ioutil.ReadFile(path)
strings.Contains(string(dat),"name")
fmt.Println("%s opened
", dat)
}
I want to find flag value from compiled binary a store it to main program variable. Something like that
var flagMain = test var versionMain = 1.0