elasticsearch,go,struct,syntax,Function,elasticsearch,Go,Struct,Syntax" /> elasticsearch,go,struct,syntax,Function,elasticsearch,Go,Struct,Syntax" />

Function 结构中缺少函数体和字符串标记

Function 结构中缺少函数体和字符串标记,function,elasticsearch,go,struct,syntax,Function,elasticsearch,Go,Struct,Syntax,我发现一些函数在Go中没有函数体。我知道这意味着围棋的外部功能。但是我在哪里可以找到boby函数呢 type Creator func(*Beat, *common.Config) (Beater, error) 我还在Go struct中找到一个字符串。这是什么意思 type BeatConfig struct { // output/publishing related configurations Output common.ConfigNamespace `config

我发现一些函数在Go中没有函数体。我知道这意味着围棋的外部功能。但是我在哪里可以找到boby函数呢

type Creator func(*Beat, *common.Config) (Beater, error)
我还在Go struct中找到一个字符串。这是什么意思

type BeatConfig struct {
    // output/publishing related configurations
    Output common.ConfigNamespace `config:"output"`
}
上述所有代码均可在elasticsearch beats中找到: 这是:

type Creator func(*Beat, *common.Config) (Beater, error)
不是一个,而是一个。它创建一个新类型(以函数类型作为其类型),它不声明任何函数,因此不需要函数体,它没有意义,并且您不能在其中提供一个函数体

例如,您可以使用它创建该类型的变量,并存储具有相同基础类型的实际函数值

例如:

type Creator func(*Beat, *common.Config) (Beater, error)

func SomeCreator(beat *Beat, config *common.Config) (Beater, error) {
    // Do something
    return nil, nil
}

func main() {
    var mycreator Creator = SomeCreator
    // call it:
    beater, err := mycreator(&Beat{}, &common.Config{})
    // check err, use beater
}
此字段声明:

Output common.ConfigNamespace `config:"output"`

包含
输出
字段的。有关更多详细信息,请参见@icza所说的,
Creator
是一个


在您的例子中,
Beat
的每个实现都实现了
Creator
接口。这是。

两个都重复。@Adrian不是重复的,因为这不是函数声明,而是类型声明。你的答案非常详细,很容易理解,我现在明白了!这让我意识到我自己的粗心。再次感谢!谢谢你的补充!!