vscode removing imports when saving file

1

I have a very simple code in GO . Using the vs code, when I save the file I'm working on, the editor removes import "math"

Follow the code

package main

import "math"

func main() {
    a := Sqrt(float64(60))
}

When you save the file, the vs code formatter for language GO is removing import math , but it is being used (in the Sqrt function).

Why is this happening? Is it an error in the code or do I need to set something up in the vs code?

    
asked by anonymous 26.06.2017 / 20:55

2 answers

1

It is not VS code that removes the import but the GO compiler, in theory GO removes all the amounts you are not using for performance issues.

When you import from a library, you have to say that you will be using it.

package main

import "fmt"

func main() {
         //bem aqui utilizando a biblioteca FMT
    a := fmt.Println("Hello")
}
    
17.07.2017 / 18:37
1

I found out how to fix the problem, I was missing the prefix math in front of the Sqrt function. Anyway, beginner language problems.

The complete code looks like this:

package main

import "math"

func main() {
    a := math.Sqrt(float64(60)) 
}
    
28.06.2017 / 16:01