Created
June 19, 2015 04:40
-
-
Save lewisou/df7aa67b85e66e843b84 to your computer and use it in GitHub Desktop.
Source Code of the client side program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
usr, err := user.Current() // Get the operating system user. | |
if err != nil { | |
log.Fatal( err ) | |
} else { | |
monitorFolder := path.Join(usr.HomeDir, monitorFolderName) // A particular folder in the home directory. | |
// Make sure the folder exists | |
if ensureFolder(monitorFolder) { | |
// fileStore is an object that caches the folder status in memory | |
fileStore := common.NewFileRecordStore(monitorFolder) | |
// Load previous state from a file, as users may shutdown the program, | |
// the program needs to restore to the previous state | |
fileStore.LoadFromFile() | |
// This is a concurrency channel. which is a bridge between file scan and the remote api call. | |
changesChannel := make(chan common.FileRecord, 10) | |
// This is a new thread, which read from the channel and call remote http api. | |
go submitToRemote(changesChannel, fileStore) | |
for { | |
// This is the main thread, which scan the folder every 5 seconds, If any changes found, send it to the channel. | |
fileStore.Scan(changesChannel) | |
// scan interval. | |
time.Sleep(folderScanInterval * time.Millisecond) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment