OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / rjeczalik / notify / example_readdcw_test.go
1 // Copyright (c) 2014-2015 The Notify Authors. All rights reserved.
2 // Use of this source code is governed by the MIT license that can be
3 // found in the LICENSE file.
4
5 // +build windows
6
7 package notify_test
8
9 import (
10         "log"
11
12         "github.com/rjeczalik/notify"
13 )
14
15 // This example shows how to watch directory-name changes in the working directory subtree.
16 func ExampleWatch_windows() {
17         // Make the channel buffered to ensure no event is dropped. Notify will drop
18         // an event if the receiver is not able to keep up the sending pace.
19         c := make(chan notify.EventInfo, 4)
20
21         // Since notify package behaves exactly like ReadDirectoryChangesW function,
22         // we must register notify.FileNotifyChangeDirName filter and wait for one
23         // of FileAction* events.
24         if err := notify.Watch("./...", c, notify.FileNotifyChangeDirName); err != nil {
25                 log.Fatal(err)
26         }
27         defer notify.Stop(c)
28
29         // Wait for actions.
30         for ei := range c {
31                 switch ei.Event() {
32                 case notify.FileActionAdded, notify.FileActionRenamedNewName:
33                         log.Println("Created:", ei.Path())
34                 case notify.FileActionRemoved, notify.FileActionRenamedOldName:
35                         log.Println("Removed:", ei.Path())
36                 case notify.FileActionModified:
37                         panic("notify: unexpected action")
38                 }
39         }
40 }