本文整理匯總了Golang中github.com/NebulousLabs/Sia/types.FileContractID.UnmarshalJSON方法的典型用法代碼示例。如果您正苦於以下問題:Golang FileContractID.UnmarshalJSON方法的具體用法?Golang FileContractID.UnmarshalJSON怎麽用?Golang FileContractID.UnmarshalJSON使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NebulousLabs/Sia/types.FileContractID
的用法示例。
在下文中一共展示了FileContractID.UnmarshalJSON方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: load
// load fetches the saved renter data from disk.
func (r *Renter) load() error {
// Load all files found in renter directory.
dir, err := os.Open(r.persistDir) // TODO: store in a subdir?
if err != nil {
return err
}
defer dir.Close()
filenames, err := dir.Readdirnames(-1)
if err != nil {
return err
}
for _, path := range filenames {
// Skip non-sia files.
if filepath.Ext(path) != ShareExtension {
continue
}
file, err := os.Open(filepath.Join(r.persistDir, path))
if err != nil {
// maybe just skip?
return err
}
_, err = r.loadSharedFiles(file)
file.Close() // defer is probably a bad idea
if err != nil {
// maybe just skip?
return err
}
}
// Load contracts, repair set, and entropy.
data := struct {
Contracts map[string]types.FileContract
Tracking map[string]trackedFile
Repairing map[string]string // COMPATv0.4.8
Entropy [32]byte
}{}
err = persist.LoadFile(saveMetadata, &data, filepath.Join(r.persistDir, PersistFilename))
if err != nil {
return err
}
if data.Tracking != nil {
r.tracking = data.Tracking
} else if data.Repairing != nil {
// COMPATv0.4.8
for nick, path := range data.Repairing {
// these files will be renewed indefinitely
r.tracking[nick] = trackedFile{RepairPath: path, EndHeight: 0}
}
}
r.entropy = data.Entropy
var fcid types.FileContractID
for id, fc := range data.Contracts {
fcid.UnmarshalJSON([]byte(id))
r.contracts[fcid] = fc
}
return nil
}
示例2: load
// load fetches the saved renter data from disk.
func (r *Renter) load() error {
// Load all files found in renter directory.
dir, err := os.Open(r.persistDir) // TODO: store in a subdir?
if err != nil {
return err
}
filenames, err := dir.Readdirnames(-1)
if err != nil {
return err
}
for _, path := range filenames {
// Skip non-sia files.
if filepath.Ext(path) != ShareExtension {
continue
}
file, err := os.Open(filepath.Join(r.persistDir, path))
if err != nil {
// maybe just skip?
return err
}
_, err = r.loadSharedFiles(file)
if err != nil {
// maybe just skip?
return err
}
}
// Load contracts, repair set, and entropy.
data := struct {
Contracts map[string]types.FileContract
Repairing map[string]string
Entropy [32]byte
}{}
err = persist.LoadFile(saveMetadata, &data, filepath.Join(r.persistDir, PersistFilename))
if err != nil {
return err
}
r.repairSet = data.Repairing
r.entropy = data.Entropy
var fcid types.FileContractID
for id, fc := range data.Contracts {
fcid.UnmarshalJSON([]byte(id))
r.contracts[fcid] = fc
}
return nil
}