Beispiel #1
0
// Wait for input and send output to client.
func takeInput(conn net.Conn) (err error) {
	for {
		query, err := bufioutil.NewReader(conn).ReadLine()
		if err != nil {
			if err.Error() == "EOF" {
				break
			}
			return errutil.Err(err)
		}

		// Do something with the query
		switch query {
		case settings.QueryUpdates:
			// Encode (send) the value.
			err = gob.NewEncoder(conn).Encode(settings.Updates)
		case settings.QueryClearAll:
			settings.Updates = make(map[string]bool)
			err = settings.SaveUpdates()
		case settings.QueryForceRecheck:
			pages, err := ini.ReadPages(settings.PagesPath)
			if err != nil {
				return errutil.Err(err)
			}
			err = page.ForceUpdate(pages)
		}
		if err != nil {
			return errutil.Err(err)
		}
	}
	return nil
}
Beispiel #2
0
func watchConfig(watcher *fsnotify.Watcher) (err error) {
	for {
		select {
		case ev := <-watcher.Event:
			if ev != nil {
				if ev.Name == settings.ConfigPath {
					// Read settings from config file.
					err = ini.ReadSettings(settings.ConfigPath)
					if err != nil {
						return errutil.Err(err)
					}
				}
				// Retrieve an array of pages from INI file.
				pages, err := ini.ReadPages(settings.PagesPath)
				if err != nil {
					return errutil.Err(err)
				}
				err = page.ForceUpdate(pages)
				if err != nil {
					return errutil.Err(err)
				}
			}
		case err = <-watcher.Error:
			if err != nil {
				return errutil.Err(err)
			}
		}
	}
}