在这个定义中:
type MyprojectV1alpha1Interface interface {
RESTClient() rest.Interface
SamplesGetter
}
Your MyprojectV1alpha1Interface
嵌入SamplesGetter
界面。
将一个接口嵌入另一个接口意味着嵌入接口的所有方法(SamplesGetter
)可以通过嵌入接口(MyprojectV1alpha1Interface
).
这意味着您可以调用任何SamplesGetter
任何实现的对象上的方法MyprojectV1alpha1Interface
.
所以一旦你得到一个MyprojectV1alpha1Interface
对象在你的temp
变量,你可以调用Samples
方法(用合适的namespace
,我无法从您发布的代码中猜测):
sampleInt := temp.Samples("namespace here")
sampleInt
然后会有一个SampleInterface
对象,这样你就可以调用Create
使用你的函数sampleInt
多变的:
sample, err := sampleInt.Create(<you should use a *v1alpha1.Sample here>)
有关接口如何工作的更多详细信息,我建议您查看官方规范和示例:
https://golang.org/ref/spec#Interface_types https://golang.org/ref/spec#Interface_types
https://gobyexample.com/interfaces https://gobyexample.com/interfaces