i am new in golang, i am coming from php.
i want to define a method on a struct for validating http request. but i have some problems about accessing struct fields.
there is my code.
package main
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
Title string
}
func main() {
request := &NewPostReq{Title: "Example Title"}
request.Validate()
request.Validate2(request)
}
when i run this code, then i getting below result
2015/07/21 13:59:50 &{}
2015/07/21 13:59:50 &{ReqAbstract:{} Title:Example Title}
is there any way to access struct fields on Validate() method like Validate2() method ?