UPDATE: I restarted VSCode and tested my code again, then tried it from the command line. I got a really long error, which starts with :
Exception 0xc0000005 0x0 0x7ffbd991a0f0 0x7ff89943445e
PC=0x7ff89943445e
signal arrived during external code execution
runtime.cgocall(0x7ff6ead942c0, 0xc000065da0)
and it ends with:
C:/Program Files/Go/src/runtime/asm_amd64.s:1650 +0x1 fp=0xc01494dfe8 sp=0xc01494dfe0 pc=0x7ff6ea9c8ac1
created by os/signal.Notify.func1.1 in goroutine 55
C:/Program Files/Go/src/os/signal/signal.go:151 +0x1f
rax 0xfff0fff
rbx 0xd075dff3a0
rcx 0x7ffbd991a0cc
rdi 0x7ff899c26100
rsi 0x2157c392b20
rbp 0xd075dfefb0
rsp 0xd075dfeea8
r8 0xd075dfefc0
r9 0xd075dff3a0
r10 0xd075dff190
r11 0x0
r12 0x100
r13 0x0
r14 0x1
r15 0x0
rip 0x7ff89943445e
rflags 0x10206
cs 0x33
fs 0x53
gs 0x2b
exit status 2
Any ideas? My code is pasted below, along with the original error I was getting.
Hi, new user here. I have a pretty simple setup with all code hosted in just one file, a go.mod file and go.sum file that don’t report errors in vscode.
When I try to run main.go, it says :
go: no Go source files
Also, when I hover over “main” in package main in main.go, it says :
This file is within module ".", which is not included in your workspace.
To fix this problem, you can add a go.work file that uses this directory.
See the documentation for more information on setting up your workspace:
https://github.com/golang/tools/blob/master/gopls/doc/workspace.md
I’ve tried making that go.work file and it removed the yellow squiggly line under “main”, but didn’t fix the issue, so I got rid of it.
Here’s the contents of main.go, which only reports one error (the yellow squiggly under main):
package main
import (
"C"
"fmt"
"io"
"net/http"
"time"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/widget"
)
func Call2(someurl string) (*http.Response, error) {
req, err := http.NewRequest(http.MethodGet, someurl, nil)
if err != nil {
fmt.Printf("Error creating request: %s", err)
return nil, err
}
client := http.Client{
Timeout: 30 * time.Second,
}
res, err := client.Do(req)
if err != nil {
fmt.Printf("Error making HTTP request: %s", err)
return nil, err
}
return res, nil
}
func tidyUp() {
fmt.Println("Exited")
}
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("Hello")
k, err := Call2("https://acre.iex.cloud/v1/data/CORE/REF_DATA?token=pk_79891f5cbcce4099ae063588956f937a")
if err != nil {
fmt.Printf("Error making HTTP request: %s", err)
return
}
defer k.Body.Close()
b, err := io.ReadAll(k.Body)
if err != nil {
fmt.Printf("Error reading response body: %s", err)
return
}
// fmt.Println(string(b))
myWindow.SetContent(widget.NewLabel(string(b)))
myWindow.Show()
myApp.Run()
tidyUp()
}
Here’s the contents of go.mod
, which reports no errors according to vscode:
module novicemodule
go 1.21.3
require fyne.io/fyne/v2 v2.4.1
require (
fyne.io/systray v1.10.1-0.20230722100817-88df1e0ffa9a // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fredbi/uri v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 // indirect
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8 // indirect
github.com/go-text/typesetting v0.0.0-20230616162802-9c17dd34aa4a // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gopherjs/gopherjs v1.17.2 // indirect
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c // indirect
github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/tevino/abool v1.2.0 // indirect
github.com/yuin/goldmark v1.5.5 // indirect
golang.org/x/image v0.11.0 // indirect
golang.org/x/mobile v0.0.0-20230531173138-3c911d8e3eda // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
)
Any ideas? All help much appreciated!