github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/signer/storage/storage.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 12:09:46</date> 10 //</624342668192780288> 11 12 // 13 14 package storage 15 16 import ( 17 "fmt" 18 ) 19 20 type Storage interface { 21 //按键存储值。0长度键导致无操作 22 Put(key, value string) 23 //get返回以前存储的值,如果该值不存在或键的长度为0,则返回空字符串 24 Get(key string) string 25 } 26 27 //短暂存储是一种内存存储,它可以 28 //不将值持久化到磁盘。主要用于测试 29 type EphemeralStorage struct { 30 data map[string]string 31 namespace string 32 } 33 34 func (s *EphemeralStorage) Put(key, value string) { 35 if len(key) == 0 { 36 return 37 } 38 fmt.Printf("storage: put %v -> %v\n", key, value) 39 s.data[key] = value 40 } 41 42 func (s *EphemeralStorage) Get(key string) string { 43 if len(key) == 0 { 44 return "" 45 } 46 fmt.Printf("storage: get %v\n", key) 47 if v, exist := s.data[key]; exist { 48 return v 49 } 50 return "" 51 } 52 53 func NewEphemeralStorage() Storage { 54 s := &EphemeralStorage{ 55 data: make(map[string]string), 56 } 57 return s 58 } 59