go语言的split go语言的框架( 六 )


2016/12/13 22:55:56.013362 beat.go:267: INFO
Home path: [/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat]
Config path: [/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat]
Data path: [/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat/data]
Logs path: [/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat/logs]
2016/12/13 22:55:56.013390 beat.go:177: INFO Setup Beat: redditbeat; Version: 6.0.0-alpha1
2016/12/13 22:55:56.013402 processor.go:43: DBGProcessors:
2016/12/13 22:55:56.013413 beat.go:183: DBGInitializing output plugins
2016/12/13 22:55:56.013417 logp.go:219: INFO Metrics logging every 30s
2016/12/13 22:55:56.013518 output.go:167: INFO Loading template enabled. Reading template file:
/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat/redditbeat.template.json
2016/12/13 22:55:56.013888 output.go:178: INFO Loading template enabled for Elasticsearch 2.x. Reading template file:
/Users/i303869/projects/private/go/src/github.com/nfrankel/redditbeat/redditbeat.template-es2x.json
2016/12/13 22:55:56.014229 client.go:120: INFO Elasticsearch url:
2016/12/13 22:55:56.014272 outputs.go:106: INFO Activated elasticsearch as output plugin.
2016/12/13 22:55:56.014279 publish.go:234: DBGCreate output worker
2016/12/13 22:55:56.014312 publish.go:276: DBGNo output is defined to store the topology.
The server fields might not be filled.
2016/12/13 22:55:56.014326 publish.go:291: INFO Publisher name: LSNM33795267A
2016/12/13 22:55:56.014386 async.go:63: INFO Flush Interval set to: 1s
2016/12/13 22:55:56.014391 async.go:64: INFO Max Bulk Size set to: 50
2016/12/13 22:55:56.014395 async.go:72: DBGcreate bulk processing worker (interval=1s, bulk size=50)
2016/12/13 22:55:56.014449 beat.go:207: INFO redditbeat start running.
2016/12/13 22:55:56.014459 redditbeat.go:38: INFO redditbeat is running! Hit CTRL-C to stop it.
2016/12/13 22:55:57.370781 client.go:184: DBGPublish: {
"@timestamp": "2016-12-13T22:54:47.252Z",
"beat": {
"hostname": "LSNM33795267A",
"name": "LSNM33795267A",
"version": "6.0.0-alpha1"
},
"counter": 1,
"type": "redditbeat"
}
第 2 段(可获 0.73 积分)
R e; 7个月前
关于命令行参数:-e记录到标准err,而-d“*”启用所有调试选择器 。有关参数的完整列表,请键入./redditbeat --help 。编码Go代码位于.go文件中(令人惊讶...)在$ GOPATH / src文件夹的项目子文件夹中 。配置类型第一个有趣的文件是config / config.go,它定义go语言的split了一个结构来声明Beat的可能参数 。至于前面的Logstash插件,让我们添加一个subreddit参数,并设置它的默认值:type Config struct {
Period time.Duration `config:"period"`
Subreddit string `config:"subreddit"`
}
var DefaultConfig = Config {
Period: 15 * time.Second,
Subreddit: "elastic",
}
第 3 段(可获 0.89 积分)
R e; 7个月前
Beater TypeBeat本身的代码在beater / redditbean.go中找到 。默认模板为Beat和三个函数创建一个struct:Beat构造函数—用来读取配置: func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) { ... }
Run 函数- 需要覆盖Beat的主要功能: func (bt *Redditbeat) Run(b *beat.Beat) error { ... }
Stop 函数管理优雅关闭: func (bt *Redditbeat) Stop() { ... }
Note 1:在Go中没有明确的接口实现 。实现了 interface 中的所有方法 , 即创建一个隐式继承关系. 出于写文档的目的,这是 Beater 接口:type Beater interface {
Run(b *Beat) error
Stop()
}
第 4 段(可获 0.93 积分)
R e; 7个月前
因此 , 由于Beat结构实现了Run和Stop , 它是一个Beater 。Note 2: 在Go中没有类的概念 , 所以方法不能在一个具体类型上声明 。但是,它存在扩展函数的概念:可以添加行为到一个类型(在单个包中)的函数 。它需要声明receiver 类型:这是在fun关键字和函数名之间完成的 - 这里是指Redditbeat类型(或者更准确地说,是一个指向Redditbeat类型的指针,但是这里有一个隐式转换) 。构造函数和Stop函数可以保持不变,无论什么特性都应该在Run函数中 。在这种情况下,功能是调用Reddit REST API并为每个Reddit帖子发送一条消息 。

推荐阅读