All Questions

208
votes
2answers
50729 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...
144
votes
1answers
24762 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...
76
votes
4answers
19554 views

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...
92
votes
4answers
36850 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: ...
50
votes
2answers
13293 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...
25
votes
2answers
4894 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...
41
votes
5answers
39323 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
747 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
535 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() { ...
43
votes
4answers
46859 views

Parsing date string in golang

I tried parsing date string "2014-09-12T11:45:26.371Z" in go lang. Code layout := "2014-09-12T11:45:26.371Z" str := "2014-11-12T11:45:26.371Z" err, t := time.Parse(layout , str) parsing time "201...

Previous Next