Unable to debug go in vscode - go

I'm not able to debug a go file in vscode. I want to debug mrcorordinator.go in package main but the main package also contain other files.Here is the main package structure.
main
diskvd.go
lockc.go
lockd.go
mrcoordinator.go
mrworker.go
pbc.go
pbd.go
while debugging mrcoordinator.go, I'm getting Error like this
Build Error: go build -o /home/sanketbondre/myspace/6.824/src/main/__debug_bin -gcflags all=-N -l .
diskvd.go:19:8: no required module provides package 6.824/diskv; to add it:
go get 6.824/diskv
lockc.go:7:8: no required module provides package 6.824/lockservice; to add it:
go get 6.824/lockservice
pbc.go:21:8: no required module provides package 6.824/pbservice; to add it:
go get 6.824/pbservice
viewd.go:8:8: no required module provides package 6.824/viewservice; to add it:
go get 6.824/viewservice (exit status 1)
Does anyone know how debug specific go file in vscode(here I want to debug mrcoordinator.go only).

Related

Golang: generating core failed: unable to load github.com

I installed golang and started with this tutorial: https://www.howtographql.com/graphql-go/1-getting-started/
When I run:
go run github.com/99designs/gqlgen generate
I get:
reloading module info
generating core failed: unable to load github.com/my-user/hackernews/graph/model - make sure you're using an import path to a package that exists
exit status 1
What is wrong with my setup?
This is my gopath
/Users/my-pc-user/go
TLDR
$ cd your_project_path/
$ print '// +build tools\npackage tools\nimport _ "github.com/99designs/gqlgen"' | gofmt > ./tools.go
$ echo 'package model' | gofmt > ./graph/model/doc.go
$ go get .
Explanation
According to a quick start guide, you should create a package with generated code that actually is already imported by your server:
package main
import (
"log"
"net/http"
"os"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"your_module_name/graph"
"your_module_name/graph/generated"
)
Because of the fact that your_module_name/graph/generated has no *.go files you cannot start a server and if you try you will get an error like:
graph/schema.resolvers.go:10:2: no required module provides package your_module_name/graph/generated; to add it:
To generate that package you will need to execute go run github.com/99designs/gqlgen generate, but there is another problem: gqlgen generates code that uses another package that is still doesn't exist yet, i.e. your_module_name/graph/model.
Additional step adding build constraints is required to not drop indirect dependency while generation process. That's why there is the first step with underscore import.
And if you put any *.go file to that directory with package directive — everything should works now:
$ cd your_project_path/
$ print '// +build tools\npackage tools\nimport _ "github.com/99designs/gqlgen"' | gofmt > ./tools.go
$ echo 'package model' | gofmt > ./graph/model/doc.go
$ go get .

use k8s deepcopy-gen generate code failed

I am going to use k8s code-generator to generator deepcopy file and my project under GOPATH/src, but i seems not work and got a problem about GOROOT.
deepcopy-gen command is deepcopy-gen -i k8s_customize_controller/pkg/apis -p k8s_customize_controller/pkg/client -v 10
output blow:
[root#centos72-k8s code-generator]# deepcopy-gen -i k8s_customize_controller/pkg/apis -p k8s_customize_controller/pkg/client -v 10
I0122 02:51:04.609157 17278 parse.go:383] importPackage k8s_customize_controller/pkg/apis
I0122 02:51:04.609359 17278 parse.go:330] addDir k8s_customize_controller/pkg/apis
I0122 02:51:04.730397 17278 parse.go:404] unable to import "k8s_customize_controller/pkg/apis": package k8s_customize_controller/pkg/apis is not in GOROOT (/usr/local/go/src/k8s_customize_controller/pkg/apis)
I0122 02:51:04.730701 17278 main.go:82] Completed successfully.
unable to import "k8s_customize_controller/pkg/apis": package k8s_customize_controller/pkg/apis is not in GOROOT
it seems this problem about GOROOT?
how to resolve this problem?
I had similar issue with an error like this:
Generating deepcopy funcs
F1018 10:51:28.259741 74132 main.go:80] Error: Failed making a parser: unable to add directory "github.com/[my-git-account]/[repo-name]/pkg/apis/v1": No files for pkg "github.com/[my-git-account]/[repo-name]/pkg/apis/v1"
The problem was that I recently moved my github golang projects folders out of the $GOPATH/src folder (which is in my case is ~/go/src), because it worked well on vanilla Ubuntu and WSL Ubuntu, but it has challenges to update packages on MacOS - I moved all my project from the folder ~/go/src/github.com/[my-git-account]
(where the code-generator expected them) to the folder ~/dev/[my-git-account].
Solution I use to fix the error above - to create a symbolic link on my current github projects folder to the $GOPATH/src/github.com:
ln -s ~/dev/[my-git-account] $GOPATH/src/github.com
This way there is a folder $GOPATH/src/github.com/[my-git-account] (provided by the sym-link) with golang projects, where code-generator can find them.
Faced one drawback of this trick - in the IDE navigation to the method can move to the linked source (within SDK package by the link - not to the source code, opened in the IDE).

socket.io-client-swift Package resolution Failed in Xcode13 Beta project

Hello to all i'm currently using the client of socket.io (https://github.com/socketio/socket.io-client-swift) with the new package manager of XCODE13 when i try to add the package using the package manager, i paste the URL of the repository(https://github.com/socketio/socket.io-client-swift) into the search bar, the package appears, then i do click into 'Add Package' button, but i get this Error (see the image):
If i use the 'Add Anyway' option in order to add the package the line import SocketIO into my view file doesn't find the package gives me an error, and i have the same result importing the package via 'Add Local' option, i get the same error.
Thank you and sorry for the English
Am i doing something wrong?
I also have problems with socket.io using Carthage in Xcode 13 and Monterey
Building scheme "SocketIO" in Socket.IO-Client-Swift.xcodeproj
Build Failed: …
…
This usually indicates that project itself failed to compile.
Edit: I fixed my issue replacing the 1200 by 1300 in the carthage workaround script

VSCode import problem with windows API call

When importing golang.org/x/sys/windows in VSCode, I can only choose SIGDescribe, nothing else.
Hovering over the import, following errors appear.
error while importing golang.org/x/sys/windows: build constraints exclude all Go files in /home/username/go/pkg/mod/golang.org/x/sys#v0.0.0-20210630005230-0f9fa26af87c/windows
could not import golang.org/x/sys/windows (no required module provides package "golang.org/x/sys/windows")compilerBrokenImport
The manual command go get golang.org/x/sys/windows gives the following error message
Command 'gopls.go_get_package' failed: Error: err: exit status 1: stderr: package golang.org/x/sys/windows: build constraints exclude all Go files in /home/username/go/pkg/mod/golang.org/x/sys#v0.0.0-20210630005230-0f9fa26af87c/windows .
I already re-installed Golang and updated GoTools in VSCode, no changes.
Goal: The following code below should work.
package main
import "golang.org/x/sys/windows"
func main() {
user32DLL := windows.NewLazyDLL("user32.dll")
}
OS: Ubuntu 21.04
GO Version: 1.16.6
Editor: VSCode 1.58.1
Make a folder somewhere something. Then make a file something/main.go:
package main
import "golang.org/x/sys/windows"
func main() {
println(windows.EVENTLOG_ERROR_TYPE == 1)
}
Then build:
go mod init something
go mod tidy
go build

Protoc-gen-gogo compiler issue with go

Step 1:- add following dependencies
github.com/gogo/protobuf/proto [ok]
github.com/gogo/protobuf/protoc-gen-gogo[ok]
github.com/gogo/protobuf/gogoproto[ok]
google.golang.org/grpc[ok]
Step 2:-
create proto file in a project
Step 3:-
change directory and type this command
protoc --gogo_out=. greet
error:=
protoc-gen-gogo: program not found or is not executable
Please specify a program using the absolute path or make sure the program is available in your PATH system variable.
--gogo_out: protoc-gen-gogo: Plugin failed with status code 1.
PLease help me
It seems you did not install protoc-gen-gogo on your system.
Install it using go get github.com/gogo/protobuf/protoc-gen-gogo and try again.
For more help refer to this - https://github.com/gogo/protobuf

Resources