Documentation
¶
Index ¶
- type Block
- type Blockchain
- type Data
- type DataString
- type DiskStore
- type Ledger
- func (l *Ledger) Add(b string, s map[string]interface{})
- func (l *Ledger) Announce(ctx context.Context, d time.Duration, async func())
- func (l *Ledger) AnnounceDeleteBucket(ctx context.Context, interval, timeout time.Duration, bucket string)
- func (l *Ledger) AnnounceDeleteBucketKey(ctx context.Context, interval, timeout time.Duration, bucket, key string)
- func (l *Ledger) AnnounceUpdate(ctx context.Context, interval time.Duration, bucket, key string, ...)
- func (l *Ledger) CurrentData() map[string]map[string]Data
- func (l *Ledger) Delete(b string, k string)
- func (l *Ledger) DeleteBucket(b string)
- func (l *Ledger) Exists(b string, f func(Data) bool) (exists bool)
- func (l *Ledger) GetKey(b, s string) (value Data, exists bool)
- func (l *Ledger) Index() int
- func (l *Ledger) LastBlock() Block
- func (l *Ledger) Persist(ctx context.Context, interval, timeout time.Duration, bucket, key string, ...)
- func (l *Ledger) String() string
- func (l *Ledger) Syncronizer(ctx context.Context, t time.Duration)
- func (l *Ledger) Update(f *Ledger, h *hub.Message, c chan *hub.Message) (err error)
- type MemoryStore
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
Index int // 区块索引
Timestamp string // 时间戳
Storage map[string]map[string]Data // 存储数据
Hash string // 当前区块哈希
PrevHash string // 前一区块哈希
}
Block 表示区块链中的每个"项目"
type DiskStore ¶
type DiskStore struct {
// contains filtered or unexported fields
}
DiskStore 磁盘存储结构体
func NewDiskStore ¶
NewDiskStore 创建新的磁盘存储 参数 d 为diskv实例
type Ledger ¶
Ledger 账本结构体
func (*Ledger) Announce ¶
Announce 持续异步更新数据到区块链。 在指定间隔发送广播, 确保异步获取的值被写入区块链 参数 ctx 为上下文,d 为时间间隔,async 为异步函数
func (*Ledger) AnnounceDeleteBucket ¶
func (l *Ledger) AnnounceDeleteBucket(ctx context.Context, interval, timeout time.Duration, bucket string)
AnnounceDeleteBucket 公告删除存储桶。当存储桶被删除时停止 接受间隔时间和最大超时时间。 这是尽力而为的,超时是必要的,否则如果有多个写入者尝试写入同一资源,可能会淹没网络请求 参数 ctx 为上下文,interval 为间隔时间,timeout 为超时时间,bucket 为存储桶名称
func (*Ledger) AnnounceDeleteBucketKey ¶
func (l *Ledger) AnnounceDeleteBucketKey(ctx context.Context, interval, timeout time.Duration, bucket, key string)
AnnounceDeleteBucketKey 公告删除存储桶中的键。当键被删除时停止 参数 ctx 为上下文,interval 为间隔时间,timeout 为超时时间,bucket 为存储桶名称,key 为键名
func (*Ledger) AnnounceUpdate ¶
func (l *Ledger) AnnounceUpdate(ctx context.Context, interval time.Duration, bucket, key string, value interface{})
AnnounceUpdate 如果状态不同,持续向区块链公告内容 参数 ctx 为上下文,interval 为间隔时间,bucket 为存储桶名称,key 为键名,value 为值
func (*Ledger) CurrentData ¶
CurrentData 返回当前账本数据(加锁)
func (*Ledger) DeleteBucket ¶
DeleteBucket 从账本删除存储桶(加锁) 参数 b 为存储桶名称
func (*Ledger) Persist ¶
func (l *Ledger) Persist(ctx context.Context, interval, timeout time.Duration, bucket, key string, value interface{})
Persist 持续向区块链公告内容,直到协调完成 参数 ctx 为上下文,interval 为间隔时间,timeout 为超时时间,bucket 为存储桶名称,key 为键名,value 为值
func (*Ledger) Syncronizer ¶
Syncronizer 启动一个goroutine,定期将区块链写入通道 参数 ctx 为上下文,t 为时间间隔
type MemoryStore ¶
MemoryStore 内存存储结构体