Home > Software engineering >  Tutorial first steps Microsoft Go
Tutorial first steps Microsoft Go

Time:03-29

I am starting to learn Go following the Microsoft tutorial https://docs.microsoft.com/es-mx/learn/modules/go-variables-functions-packages/4-packages The program runs and displays the result as in the tutorial, but the two problems that it is marking me cause me concern. I do not want to continue without understanding what this detail is due to, someone who has also happened to it, or who helps me to know what it is due to, I will be very grateful.

package main

import (
    "fmt"
    "github.com/x0z38/calculator"   
    "rsc.io/quote"
)
func main(){
    total := calculator.Sum(3, 5)
    fmt.Println(total)
    fmt.Println("Version: ", calculator.Version)
    fmt.Println(quote.Hello())
    
}

I leave you the image where the error is marked in red lines in the editor enter image description here

I leave the image of the two problemsenter image description here

According to what I understood is that it does not find those files in any of the mentioned paths, but both files if I have them inside this path: C:\Projects\Go\src. My GOPATH environment variable is: C:\Projects\Go

CodePudding user response:

Golang has two ways to manage dependencies: old and new. Switching between them is usually done automatically.

Visual Sudio Code tries to check for dependencies using the old way. But I see you have go.mod and go.sum files which means you are using the new way (the Golang module system).

The environment variable GO111MODULE is used to switch between dependency control modes. It has 3 values: auto, on, off. The default is auto.

What you see is just a syntax highlighting problem and not a compilation or execution error.

CodePudding user response:

Ok this is what I did: First: Run go mod tidy as suggested by Mushroomator in my root project, and it didn't work Second: remove the GOPATH environment variable, since as JimB commented it is no longer used, and it didn't work either.

Now, this is where I feel a bit confused, because maybe I did what they asked me to do but I don't know how to explain it.

So, it works and no longer shows a syntax error. Delete the GOPATH environment variable, SET GOMODULE111=on, and take out the Projects/Go directory where I have all the files and put it on the desktop and mark this syntax error enter image description here

Google Todo Imágenes Noticias Shopping Vídeos Más Herramientas

Cerca de 1,260,000,000 resultados (0.39 segundos) Español Inglés

Now, as you can see, I open vscode directly in the helloworld directory, and the syntax error disappears, but I wanted to have it open directly from the src directory to see everything I've learned so far enter image description here

  •  Tags:  
  • go
  • Related