使用Windows 11专业版,安装围棋使用的是installer. 以下是我的main.go文件: 主程序包
import (
"fmt"
"time"
)
func main() {
fmt.Println("Hello world")
time.Sleep(2 * time.Second)
}
以及我能想到的所有相关信息:
Powershell version:
PS C:\Users\fares.alghazy\go\src> $PSVersionTable.PSVersion
个
主要次要内部版本修订
5 1 22621 1 778
GO extension settings.json:个
{
"explorer.confirmDelete": false,
"terminal.integrated.scrollback": 100000,
"editor.minimap.enabled": false,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"workbench.editorAssociations": {
"*.db": "default",
"*.docx": "default"
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[php]": {
"editor.defaultFormatter": "Sophisticode.php-formatter"
},
"editor.formatOnSave": true,
"prettier.tabWidth": 4,
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[dockercompose]": {
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
},
"typescript.updateImportsOnFileMove.enabled": "always",
"javascript.updateImportsOnFileMove.enabled": "always",
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"diffEditor.ignoreTrimWhitespace": false,
"workbench.startupEditor": "none",
"[vue]": {
"editor.defaultFormatter": "Vue.volar"
},
"audioCues.lineHasBreakpoint": "off",
"audioCues.lineHasError": "off",
"audioCues.lineHasInlineSuggestion": "off",
"audioCues.noInlayHints": "off",
"audioCues.onDebugBreak": "off",
"audioCues.volume": 0,
"audioCues.lineHasFoldedArea": "off",
"go.gopath": "C:\\Users\\myuser\\go",
"go.goroot": "C:\\Program Files\\Go",
"files.autoSave": "afterDelay",
"go.alternateTools": {
}
}
System/Directory Info:个
PS C:\Users\myuser\go\src> pwd
C:\Users\myuser\go\src
PS C:\Users\myuser\go\src> ls
Directory: C:\Users\myuser\go\src
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 28-Jul-23 12:00 PM 122 main.go
PS C:\Users\myuser\go\src> go version
go version go1.20.6 windows/amd64
PS C:\Users\myuser\go\src> go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\myuser\AppData\Local\go-build
set GOENV=C:\Users\myuser\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\myuser\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\myuser\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.6
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\myuser~1.ALG\AppData\Local\Temp\go-build1704880455=/tmp/go-build -gno-record-gcc-switches
The problem:个
一百零二
go run main.go
个
Expected output:
> Hello world
Received output:
终端停顿(即使没有时间.睡眠)然后什么也不会发生
Attempted fixes:
1- Attempted to use go build then running the exe, no output was received
2- Attempted to build then redirect the output to a file:
go build main.go
.\main.exe >output.txt
output.txt was created but empty
3- Checked console encoding : Active code page: 65001
4-Disable Antivirus or Security Software: I am using standard windows security features, no 3rd party security software installed
I have even tried re-installing the Go software, restarting my pc, restarting VS code, etc
Why is my code not showing output? What can I do to fix it?
Update 1:
As instructed by @mkopriva:
go mod init my_app produce the following go.mod file:
module my_app
go 1.20
我的新目录是:
PS C:\Users\myuser\Desktop\Development\go\my_app> ls
Directory: C:\Users\myuser\Desktop\Development\go\my_app
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 28-Jul-23 1:14 PM 27 go.mod
-a---- 28-Jul-23 1:15 PM 125 main.go
使用Go Run Main.Go或构建然后运行没有任何变化.仍然得不到输出.