github.com/karalabe/go-ethereum@v0.8.5/eth/peer_util.go (about)

     1  package eth
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"github.com/ethereum/go-ethereum/ethutil"
     7  )
     8  
     9  func WritePeers(path string, addresses []string) {
    10  	if len(addresses) > 0 {
    11  		data, _ := json.MarshalIndent(addresses, "", "    ")
    12  		ethutil.WriteFile(path, data)
    13  	}
    14  }
    15  
    16  func ReadPeers(path string) (ips []string, err error) {
    17  	var data string
    18  	data, err = ethutil.ReadAllFile(path)
    19  	if err != nil {
    20  		json.Unmarshal([]byte(data), &ips)
    21  	}
    22  	return
    23  }