For some reason, I get the following errors when installing the cloud.google.com/go/bigquery package. I'm a Go noob, so I assume I'm doing something wrong. I was wondering if anyone was able to replicate, or could point me in the direction about how to resolve these errors? For example, is using a bool type in place of a *bool legal in prior versions of Go? Perhaps this is a bug in the Google package?
$ go get -u cloud.google.com/go/bigquery
# cloud.google.com/go/bigquery
gocode/src/cloud.google.com/go/bigquery/query.go:166:22: cannot use true (type bool) as type *bool in assignment
gocode/src/cloud.google.com/go/bigquery/query.go:168:22: cannot use false (type bool) as type *bool in assignment
gocode/src/cloud.google.com/go/bigquery/query.go:199:15: cannot use qq.UseLegacySql (type *bool) as type bool in field value
gocode/src/cloud.google.com/go/bigquery/query.go:200:22: invalid operation: ! *bool
Looks like someone pushed a broken change to the Go BigQuery client last night.
https://github.com/GoogleCloudPlatform/google-cloud-go/commit/c718c274c122d2ca258bb8f93830d820cbb2160d
Should be fixed now. However, if you're using dep for Go dependency management, it looks like you'll need to set the revision like so in Gopkg.toml (if you are trying to use v0.21.0 of the GoogleCloudPlatform/google-cloud-go client):
[[constraint]]
name = "cloud.google.com/go"
revision = "c718c274c122d2ca258bb8f93830d820cbb2160d"
Sad times.
Related
I've been playing with uprobes. In order to probe a specific object in runtime, I need to know the size of internal go struct. In my case, the poll.FD. I could count each nested struct manually, but this could increase the complexity if we are working with a lot nested struct.
My first attempt was to use dlv expression , len <variable>. Didn't work Command failed: command not available
My second attempt was to create a program to extract this information:
package main
import (
"fmt"
"internal/poll"
"unsafe"
)
func main() {
fmt.Println("size of internal/poll FD struct:", unsafe.Sizeof(poll.FD{}))
}
When I compile the code above, the following message is shown:
main.go:7:2: use of internal package internal/poll not allowed
Am I missing something? Is there a better way get that information?
You can try do it by Testing in same package, in order to pass this limitation.
unsafe.Sizeof(reflect.ValueOf(<nested struct>)) is this what you're looking for to get the size of nested struct?
PS:This may not be answer but I can't comment.
$ go get -u github.com/metaleap/go-xsd/xsd-makepkg
/home/mypc/go/src/github.com/metaleap/go-util/fs/watcher-default.go:32:22: undefined: fsnotify.FileEvent
/home/mypc/go/src/github.com/metaleap/go-util/fs/watcher-default.go:64:35: undefined: fsnotify.FileEvent
/home/mypc/go/src/github.com/metaleap/go-util/fs/watcher-default.go:72:44: undefined: fsnotify.FileEvent
/home/mypc/go/src/github.com/metaleap/go-util/fs/watcher-default.go:79:18: me.Event undefined (type *Watcher has no field or method Event)
/home/mypc/go/src/github.com/metaleap/go-util/fs/watcher-default.go:83:21: cannot assign type func(<T>) to onEvt (type func(<T>)) in range
/home/mypc/go/src/github.com/metaleap/go-util/fs/watcher-default.go:97:18: me.Error undefined (type *Watcher has no field or method Error)
/home/mypc/go/src/github.com/metaleap/go-util/fs/watcher-default.go:119:15: me.Watch undefined (type *Watcher has no field or method Watch)
github.com/metaleap/go-xsd is "stale since 2013" so its not too suprising it no longer works. If you check github you will see the comment "MAINTAINED FOR YEARS NOW: try the forks if running into issues. link"
In this case the reason for the error you are getting is that github.com/metaleap/go-xsd/xsd-makepkg uses https://github.com/metaleap/go-util. go-util imports github.com/go-forks/fsnotify and, on line 32 in watcher-default.go, attempts to use OnEvent []func(evt *fsnotify.FileEvent). Unfortunately in the time since go-util was released the fsnotify package has been updated and no longer has FileEvent (removed some time around 2014).
I would suggest finding an alternative package. If you really want to use this one you could retrieve an early (pre 1.0) version of fsnotify (but I would not advise it as there have probably been a lot of fixes since then).
Note: More modern packages using go modules should not suffer from this issue (because dependencies can be locked to a specific version).
Currently I am using protobuf version 2 in my project. So far all of the messages are working great; however I have hit a road block trying to use the 'map' keyword.
The TLDR usage behind needing the map, is that I want to pass some JSON key/value pairs to my server to do a lookup, and potential log of data to a server (which uses a JSON message interface).
I am currently using the backwards compatibility method that is recommend on the docs page: https://developers.google.com/protocol-buffers/docs/proto#maps
What I would like to understand is why is the following declaration of my message (using maps) failing to compile? I am using the following veriosn of the protoc compiler: '# protoc --version => libprotoc 2.6.1'
message MapFieldEntry {
optional string key = 1;
optional string value = 2;
}
message Lookup {
repeated MapFieldEntry map_field = 1;
map<string, string> test_map = 2;
}
The error I receive is as follows (the errors don't make sense to me considering the documentation of the map feature):
Expected "required", "optional", or "repeated".
Expected field name.
I have tried adding syntax="proto2"; at the top, but I still get the error.
Edit:
Just as a note; the issue I am having is regarding the second argument of the Lookup message. The first argument is what I am currently using as a work around.
I found someone else with a similar issue on git:
https://github.com/google/protobuf/issues/799
The response is:
The maps syntax is only supported starting from v3.0.0. The "proto2"
in the doc is referring to the syntax version, not protobuf release
version. v3.0.0 supports both proto2 syntax and proto3 syntax while
v2.6.1 only supports proto2 syntax. For all users, it's recommended to
use v3.0.0-beta-1 instead of v2.6.1.
So it looks like to fix your problem, you should use protoc 3, instead of 2.6.1.
And keep your syntax=proto2 at the top of your file to precise this is the proto2 syntax that you use.
Could you try and let me know if this work? this is an interesting question as the official doc does not mention it.
I do not see where s is defined. Guru will not tell me. All I get is "no object for identifier" but it knows about the k right beside it. Here is a snippet that is typical of the linked code:
func getIndexAndRemainder(k uint64) (uint64, uint64) {
return k / s, k % s
}
The one letter variable name definitely makes it harder to grep around for. I have looked for the usual suspects: var s uint64, s := ..., and nothing. Clearly it needs to be a global value defined somewhere.
This leaves me with two questions:
Where is s coming from?
How would I find it without asking here?
EDIT:
For others who stumble on this.
Guru failed me because I did not checkout the source for the package under a proper Go workspace by placing the git clone under /some/path/src and setting the GOPATH to /some/path. So while I thought GOPATH=. guru definition s would work, the GOPATH was ignored. guru could find k because it is in the file but it did not know how to look in other files.
My grep failed cause const uses a simple = not a :=. I will remember this when grepping in the future.
It is defined in go-datastructures/bitarray/block.go:
// s denotes the size of any element in the block array.
// For a block of uint64, s will be equal to 64
// For a block of uint32, s will be equal to 32
// and so on...
const s = uint64(unsafe.Sizeof(block(0)) * 8)
As the variable s was not defined in the function, and it was not prefixed by a package name or alias, it had to be a global (variable or constant) of the bitarray package.
Once that was known, I went through every file in the folder go-datastructures/bitarray that was not suffixed with _test and I looked for a top-level declaration for s.
It's defined in go-datastructures/bitarray/block.go, line #33:
const s = uint64(unsafe.Sizeof(block(0)) * 8)
"Modern" IDEs with Go support usually have the ability to go to the definition of a symbol / identifier your cursor is at or what you click on. For example in Atom with the Go-plus plugin you can go to the definition by holding down the CTRL key while clicking.
These IDEs use the godef open source tool to find the definition source file and line, you may also use it directly. You can find the godef documentation here: https://godoc.org/github.com/rogpeppe/godef
Another tool, guru is also capable of tracking the definition of it. Both guru and godef works in Atom, and were able to jump to block.go, to the definition of s. But it's much easier to use an "armored" IDE and just do a simple click.
Also note that the success of using grep and patterns is limited, as variable and constant declarations can be grouped, and the following are also valid declarations:
var (
longer = 3
s = uint64(3)
)
Or:
var (
s = someExpression
longer = 3
)
Or:
const (
p = uint64(iota)
s
x
)
Seems go has autocomplete data gettable via some go program. any example how to? e.g. i have file test.go and line:column 10:12. this pos (10:12) is after some func name, e.g. "getn" - can I get list of all funcs which begin with "getn".
ie, get autocomplete data.
Tks to comment. Answer is gocode https://github.com/nsf/gocode (it has document inside zip).