zs5460 / watcher

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

watcher

Package watcher implements a simple file monitor that calls a callback function when a file is modified, typically used to automatically load configuration files.

simple

package main

import (
 "fmt"
 "log"

 "github.com/zs5460/jmc"
 "github.com/zs5460/watcher"
)

type config struct {
 Listen  string
 Version string
}

var cfg config

func main() {
 w, err := watcher.New("config.json", loadConfig)
 if err != nil {
  log.Fatal(err)
 }
 w.Start()

 // or use Must
 watcher.Must("config.json", loadConfig).Start()

 <-make(chan struct{})
}

func loadConfig() {
 jmc.MustLoadConfig("config.json", &cfg)
 fmt.Printf("%#v\n", cfg)
}

License

Released under MIT license, see LICENSE for details.

About

License:MIT License


Languages

Language:Go 100.0%