Home >Backend Development >Golang >How to Access Fields of an Embedded Struct within a Containing Struct Method?
The question arises when trying to access fields of an embedded struct within a method defined on the containing struct. Consider the following code:
<code class="go">import "log" type ReqAbstract struct{} func (r *ReqAbstract) Validate() error { log.Printf("%+v", r) return nil } func (r *ReqAbstract) Validate2(req interface{}) error { log.Printf("%+v", req) return nil } type NewPostReq struct { ReqAbstract</code>
The above is the detailed content of How to Access Fields of an Embedded Struct within a Containing Struct Method?. For more information, please follow other related articles on the PHP Chinese website!