I'm trying to import some modules after the declarations in Go.
For instance, I've tried importing the time time after declaring a variable but that doesn't work , can someone please tell me why that happens in Go?
This works:
package main
import (
"fmt"
)
import "time";
var test = "testing"
func main() {
currtime := time.Now()
fmt.Println(test)
fmt.Println(currtime)//Output: 16:44:53
}
But thid doesn't:
package main
import (
"fmt"
)
var test = "testing"
import "time"
func main() {
currtime := time.Now()
fmt.Println(test)
fmt.Println(currtime)//Output: 16:44:53
}
The error is "non-declaration statement outside function body". Why does that happen in Go?