Quantcast
Channel: Initialize embedded struct in Go - Stack Overflow
Browsing latest articles
Browse All 5 View Live

Answer by Vance Palacio for Initialize embedded struct in Go

Just for completeness sake, I'll add another example as well. Based on the comment from @VictorThis example shows another way recommended https://play.golang.org/p/Gbn8e6CTVi_ctype MyRequest struct {...

View Article



Answer by Matt for Initialize embedded struct in Go

As Jeremy shows above, the "name" of an anonymous field is the same as the type of the field. So if the value of x were a struct containing an anonymous int, then x.int would refer to that field.

View Article

Answer by zzzz for Initialize embedded struct in Go

What about:func New(origRequest *http.Request, pathParams map[string]string) *MyRequest { return &MyRequest{*origRequest, pathParams}}It shows that instead ofNew(foo, bar)you might prefer...

View Article

Answer by Jeremy Wall for Initialize embedded struct in Go

req := new(MyRequest)req.PathParams = pathParamsreq.Request = origRequestor...req := &MyRequest{ PathParams: pathParams Request: origRequest}See: http://golang.org/ref/spec#Struct_types for more...

View Article

Initialize embedded struct in Go

I have the following struct which contains a net/http.Request:type MyRequest struct { http.Request PathParams map[string]string}Now I want to initialize the anonymous inner struct http.Request in the...

View Article

Browsing latest articles
Browse All 5 View Live




Latest Images