// Get will retrieve a message from the store, the one associated with
// the provided key value.
Get will retrieve a message from the store, the one associated with
the provided key value.
// Get will retrieve a message from the store the one associated with // the provided key value .
func (store *FileStore) Get(key string) packets.ControlPacket {
	store.RLock()
	defer store.RUnlock()
	if !store.opened {
		ERROR.Println(STR, "trying to use file store, but not open")
		return nil
	}
	filepath := fullpath(store.directory, key)
	if !exists(filepath) {
		return nil
	}
	mfile, oerr := os.Open(filepath)
	chkerr(oerr)
	msg, rerr := packets.ReadPacket(mfile)
	chkerr(mfile.Close())
	if rerr != nil {
		newpath := corruptpath(store.directory, key)
		WARN.Println(STR, "corrupted file detected:", rerr.Error(), "archived at:", newpath)
		if err := os.Rename(filepath, newpath); err != nil {
			ERROR.Println(STR, err)
		}
		return nil
	}
	return msg
}
func ( store * FileStore ) Get ( key string ) packets . ControlPacket { store . RLock ( ) defer store . RUnlock ( ) if ! store . opened { ERROR . Println ( STR , " " ) return nil } filepath := fullpath ( store . directory , key ) if ! exists ( filepath ) { return nil } mfile , oerr := os . Open ( filepath ) chkerr ( oerr ) msg , rerr := packets . ReadPacket ( mfile ) chkerr ( mfile . Close ( ) ) if rerr != nil { newpath := corruptpath ( store . directory , key ) WARN . Println ( STR , " " , rerr . Error ( ) , " " , newpath ) if err := os . Rename ( filepath , newpath ) ; err != nil { ERROR . Println ( STR , err ) } return nil } return msg }
Get will retrieve a message from the store, the one associated with
the provided key value.
Get will retrieve a message from the store the one associated with the provided key value .
// Message was unreadable, return nil