Tutorial first steps Microsoft Go

Issue

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

Solution

What I’ve learned is that you want vscode(or gopls) to correctly identify a multi-module project. Please refer to this(your are using Go1.18): https://github.com/golang/tools/blob/master/gopls/doc/workspace.md

And more about go modules: https://go.dev/blog/using-go-modules

And go workspace: https://go.dev/doc/tutorial/workspaces

Hope those could help you.

Answered By – kocoler

Answer Checked By – Timothy Miller (GoLangFix Admin)

Leave a Reply

Your email address will not be published.