This repository has been archived on 2020-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
n3rdpad-agent/agent.go

52 lines
1.1 KiB
Go
Raw Normal View History

2016-07-05 00:20:17 +02:00
package main
import (
2016-07-12 22:52:48 +02:00
"fmt"
"log"
"os"
"path"
2016-07-05 00:20:17 +02:00
2016-07-12 22:52:48 +02:00
"github.com/fsnotify/fsnotify"
2016-07-05 00:20:17 +02:00
)
func watchForConfigChanges() {
2016-07-12 22:52:48 +02:00
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
defer watcher.Close()
2016-07-05 00:20:17 +02:00
2016-07-12 22:52:48 +02:00
done := make(chan bool)
go func() {
for {
select {
case event := <-watcher.Events:
log.Println("event: ", event)
if event.Op&fsnotify.Write == fsnotify.Write {
log.Println("modified file:", event.Name)
}
case err := <-watcher.Errors:
log.Println("error:", err)
}
}
}()
2016-07-05 00:20:17 +02:00
2016-07-12 22:52:48 +02:00
// The configuration file need to be in the same directory as the binary.
// Later on, we can add other paths, where the file can be placed (like as a
// dotfile in the home directory or in the .config/n3rdpad/ folder or other
// places where windows will put it).
config_path, err := os.Getwd()
config_file := path.Join(config_path, "keymap.conf")
err = watcher.Add(config_file)
if err != nil {
log.Fatal("Can't find the 'keymap.conf' configuration file. Please create one.")
}
<-done
2016-07-05 00:20:17 +02:00
}
func main() {
2016-07-12 22:52:48 +02:00
fmt.Printf("Ready\n")
watchForConfigChanges()
2016-07-05 00:20:17 +02:00
}