FAQ
Hi there,

I'm new to Go and I can't figure out an error I'm having.

I have this code (http://play.golang.org/p/WWQvFsc1or):

package main

func MyFunction(ids []uint32, fields map[string]string) interface{} {

data := struct {
Ids []uint32 `json:"ids"`
_ map[string]string
}{
ids,
fields,
}

return data
}

But when I compile I get the following error:

prog.go:5: cannot refer to blank field or method

What am I doing wrong? What does the message mean exactly? I understand
where the error comes from (I'm using the blank identifier), but I don't
understand why it doesn't work.



*Also, here's a bit of context as to why I'm trying to write such code:*
The actual code I'm trying to compile is more complicated, I stripped out
all the noise to make it easy to read. The actual code doesn't return an
interface{}. I did this in my simplified example to get the code to compile.

In the actual code, I'm trying to JSON encode some data and get the
following JSON string:

{"ids":[12345,12345],"somefieldsinthemap":"thevalueofthefield"}.

*Another digression:*
In my original code, I have written testing files. When I run go test, the
error I get is the following:

# github.com/xxx/xxx/blabla
/var/folders/hz/867wldps5hzfmtk5ygyv8p000000gn/T/go-build872258806/
github.com/xxx/xxx/blabla/_test/_obj_test/*blabla.go:176: cannot refer to
blank field or method*
FAIL github.com/xxx/xxx/blabla [build failed]

However, running go build returns:
# github.com/xxx/xxx/blabla
./*blabla.go:160: cannot refer to blank field or method*

Why are the lines reported (160 and 176) not the same?

Thank you for your help!
-Hugues

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 4 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 6, '14 at 3:32p
activeOct 6, '14 at 5:37p
posts4
users2
websitegolang.org

2 users in discussion

Hugues Alary: 3 posts Ian Lance Taylor: 1 post

People

Translate

site design / logo © 2022 Grokbase