beehive
Overview
看一下作者本人的注释
// Package bees is Beehive's central module system.
beehive 非常有趣的在于各逻辑的解耦设计,这不仅让本身功能操作简单,也让扩展变得关注点少了很多,只需要一点学习成本就可以扩展自己的 beehive
首先解释一下 bee hive 中 的概念
bee
代表的是我们常见的 Worker
也就是说,实际的行为是由这些 小蜜蜂执行的。他们就类似于采蜜的工人,采集到了之后统一放回来处理
hive
是蜂房,也就是我们常见的 WorkerPool
不同的是,她更像一个 Facotry
,什么意思呢?她可以创建专属的 bee
。在极少的配置下,比如只需要配置上一个 token
即可。就可以生成一只 bee
专门针对某一种蜜工作了。
chain
又是什么? chain
就是链接事件与处理的工具,我们认为 bee
采回蜜是一个事件,总不可能采回来啥都不干吧。针对不同的 蜜 我们就有不同的反应,就有不同的 action
比如某人的 blog 更新了 ,rss bee 接收到了之后飞回来,我们就可以再要求 email bee 把这其中的信息通过邮件发给我们或者我们想发给的人。
这就需要 chain
来联系 event
和 action
了
Landscape
API Register
成组的 API 实现了 Resource 接口注册到 Container 的路由 Route 中。
帮助理解
在文件中写好了 作者 实现的 Handle 的实现来注册 http 请求
API 只是供调用,逻辑重点在 bees 这个包里的实现。
Bee
首先是有的接口
// BeeInterface is an interface all bees implement.
type BeeInterface interface {
// Name of the bee
Name() string
// Namespace of the bee
Namespace() string
// Description of the bee
Description() string
// SetDescription sets a description
SetDescription(s string)
// Config returns this bees config
Config() BeeConfig
// Options of the bee
Options() BeeOptions
// SetOptions to configure the bee
SetOptions(options BeeOptions)
// ReloadOptions gets called after a bee's options get updated
ReloadOptions(options BeeOptions)
// Activates the bee
Run