All Questions

195
votes
2answers
47977 views

What are the use(s) for tags in Go?

In the Go Language Specification, it mentions a brief overview of tags: A field declaration may be followed by an optional string literal tag, which becomes an attribute for all the fields in t...
133
votes
1answers
22309 views

Pointers vs. values in parameters and return values

In Go there are various ways to return a struct value or slice thereof. For individual ones I've seen: type MyStruct struct { Val int } func myfunc() MyStruct { return MyStruct{Val: 1} } fu...
74
votes
4answers
18237 views

Go: What's the meaning of interface{}?

I'm new to interfaces and trying to do SOAP request by github I don't understand the meaning of Msg interface{} in this code: type Envelope struct { Body `xml:"soap:"` } type Body struc...
89
votes
4answers
34323 views

Type converting slices of interfaces in go

I'm curious why go does't implicitly convert []T to []interface{} when it will implicitly convert T to interface{}. Is there something non-trivial about this conversion that I'm missing? Example: ...
25
votes
2answers
4468 views

Hiding nil values, understanding why golang fails here

I fail to understand how to correctly assure that something is not nil in this case: package main type shower interface { getWater() []shower } type display struct { SubDisplay *display } func...
47
votes
2answers
11879 views

Go json.Marshal(struct) returns "{}"

type TestObject struct { kind string `json:"kind"` id string `json:"id, omitempty"` name string `json:"name"` email string `json:"email"` } func TestCreateSingleItemResponse(t *tes...
38
votes
5answers
35971 views

Go: multiple value in single-value context

Due to error handling in Go, I often end up with multiple values functions. So far, the way I have managed this has been very messy and I am looking for best practices to write cleaner code. Let's sa...
14
votes
2answers
720 views

My structures are not marshalling into json

I am using Go 1.0.3 on Mac OS X 10.8.2, and I am experimenting with the json package, trying to marshal a struct to json, but I keep getting an empty {} json object. The err value is nil, so nothing ...
6
votes
2answers
493 views

What's wrong with this golang code?

While SayHello() executes as expected, the goroutine prints nothing. package main import "fmt" func SayHello() { for i := 0; i < 10 ; i++ { fmt.Print(i, " ") } } func main() { ...
108
votes
4answers
85301 views

How to use custom packages in golang?

I'm trying to create and use a custom package in Go. It's probably something very obvious but I cannot find much information about this. Basically, I have these two files in the same folder: mylib.go...

Previous Next