I need output like
0 - os.O_APPEND - 1024
1 - os.O_CREATE - 64
2 - os.O_EXCL - 128
3 - os.O_RDONLY - 0
4 - os.O_RDWR - 2
5 - os.O_SYNC - 1052672
6 - os.O_TRUNC - 512
7 - os.O_WRONLY - 1
I am able to to do half of it with
func main() {
a := []int{os.O_APPEND,os.O_CREATE,os.O_EXCL,os.O_RDONLY,os.O_RDWR,os.O_SYNC,os.O_TRUNC,os.O_WRONLY}
for index, value := range a {
fmt.Printf("%d - - %d\n", index, value)
}
}
which gave me output
0 - - 1024
1 - - 64
2 - - 128
3 - - 0
4 - - 2
5 - - 1052672
6 - - 512
7 - - 1
and the other half of it with
func main() {
a := []string{"os.O_APPEND","os.O_CREATE","os.O_EXCL","os.O_RDONLY","os.O_RDWR","os.O_SYNC","os.O_TRUNC","os.O_WRONLY"}
for index, value := range a {
fmt.Printf("%d - %-15s -\n", index, value)
}
}
which gave me the output
0 - os.O_APPEND -
1 - os.O_CREATE -
2 - os.O_EXCL -
3 - os.O_RDONLY -
4 - os.O_RDWR -
5 - os.O_SYNC -
6 - os.O_TRUNC -
7 - os.O_WRONLY -
How can I get the desired output ?
Update
As I'm thinking about it, I'm getting an idea for solving it with an array of empty interface and then type asserting on each element of the array of empty interface, once with string to get the string, and once with int to get the value of int, but I don't know how to do that.