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 following function:
func New(origRequest *http.Request, pathParams map[string]string) *MyRequest { req := new(MyRequest) req.PathParams = pathParams return req }
How can I initialize the inner struct with the parameter origRequest
?
req := new(MyRequest) req.PathParams = pathParams req.Request = origRequest
or...
req := &MyRequest{ PathParams: pathParams Request: origRequest }
See: http://golang.org/ref/spec#Struct_types for more about embedding and how the fields get named.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With