I was researching on topic to analyze the codes that are executed with different inputs in Go. Assuming I have following code:
1 package main
2 import "fmt"
3 func main() {
4 var i int
5 _, err := fmt.Scanf("%d", &i)
6 if i%2 == 0 {
7 fmt.Println("input is even")
8 } else {
9 fmt.Println("input is odd")
10 }
11 }
The codes that are executed are based on the value of input. If your input is an even number, like 20, then the output should be [1, 2, 3, 4, 5, 6, 7, 11]
. Otherwise, if the value of input is odd, like 21, then output will be [1, 2, 3, 4, 5, 6, 8, 9, 10, 11]
.
I am looking for a way in Go to print out the line numbers executed in runtime. If there are other imported go files, the line numbers that are executed in those files should be also printed out.