Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ByteView ¶
type ByteView struct {
// contains filtered or unexported fields
}
A ByteView holds an immutable view of bytes.
type DataGetter ¶
DataGetter 对外回调函数接口 A Getter loads data from DB or etc. for a key.
type GetterFunc ¶
定义一个函数类型 F,并且实现接口 A 的方法,然后在这个方法中调用自己。 这是 Go 语言中将其他函数(参数返回值定义与 F 一致)转换为接口 A 的常用技巧。 A GetterFunc implements DataGetter with a function.
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
一个group可以被认为一个缓存的命名空间 每一个group拥有一个唯一的name,这样可以创建多个group
func (*Group) GetCacheBytes ¶
getLocally 从自定义的回调函数中获取缓存中没有的资源
func (*Group) RegisterPicker ¶
func (g *Group) RegisterPicker(picker NodePicker)
将实现了 NodePicker 接口的 节点选择器 注入到 Group 中
type HTTPPool ¶
type HTTPPool struct {
// contains filtered or unexported fields
}
HTTPPool implements PeerPicker for a pool of HTTP peers.
func NewHTTPPool ¶
func (*HTTPPool) PickNode ¶
func (p *HTTPPool) PickNode(key string) (NodeGetter, bool)
PickNode method picks a node according to key 具体的 key,选择节点,返回节点对应的HTTP处理器(NodeGetter)。
func (*HTTPPool) ServeHTTP ¶
func (p *HTTPPool) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handle all http requests
func (*HTTPPool) SetNodes ¶
Set the pool's list of nodes' key. example: key=http://10.0.0.1:9305
type NodeGetter ¶
type NodeGetter interface { // 用于从对应 group 查找对应key的缓存值 HTTPGet(group, key string) ([]byte, error) Get(*pb.Request, *pb.Response) error }
NodeGetter 节点处理器
type NodePicker ¶
type NodePicker interface { // 利用一致性哈希算法,根据传入的 key 选择相应节点 // 并返回节点处理器NodeGetter。 PickNode(key string) (NodeGetter, bool) }
NodePicker 节点选择器