How to determine the method set of an interface in Golang?
问题 How would one print the method set of the following interface? type Searcher interface { Search(query string) (found bool, err error) ListSearches() []string ClearSearches() (err error) } Such that Search ListSearches ClearSearches is printed out? (Without knowledge of a concrete type which implements it). 回答1: reflect package is the right tool for this.Using reflection one can get the type information of a variable without knowing the type before hand . Here is a code snippet showing how to