Пример #1
0
// transportUUIDInStorage returns the uuid stored in storage or
// creates a new random uuid and stores it.
func transportUUIDInStorage(storage util.Storage) string {
	uuid, err := storage.Get("uuid")
	if len(uuid) == 0 || err != nil {
		str := util.RandomHexString()
		uuid = []byte(netio.MAC48Address(str))
		err := storage.Set("uuid", uuid)
		if err != nil {
			log.Fatal(err)
		}
	}
	return string(uuid)
}
Пример #2
0
// loads load the id, version and config hash
func (cfg *Config) load(storage util.Storage) {
	if b, err := storage.Get("uuid"); err == nil {
		cfg.id = string(b)
	}

	if b, err := storage.Get("version"); err == nil {
		cfg.version = to.Int64(string(b))
	}

	if b, err := storage.Get("configHash"); err == nil {
		cfg.configHash = b
	}
}
Пример #3
0
// save stores the id, version and config
func (cfg *Config) save(storage util.Storage) {
	storage.Set("uuid", []byte(cfg.id))
	storage.Set("version", []byte(fmt.Sprintf("%d", cfg.version)))
	storage.Set("configHash", []byte(cfg.configHash))
}