func NewCfg(fname string, logger *dns.Logger) (c *Cfg, err error) {
	x := &Cfg{cfg: &File{}, logger: logger}
	if x.mfile, err = fileutil.NewGoMFile(fname, os.O_RDONLY, 0444, 0); err != nil {
		return
	}

	if err = x.cfg.Load(fname); err != nil {
		return
	}

	x.mfile.SetHandler(func(file *os.File) (err error) {
		if _, err = file.Seek(0, 0); err != nil {
			return
		}

		buf := []byte{}
		if buf, err = ioutil.ReadAll(file); err != nil {
			return
		}

		if err = x.cfg.LoadString(fname, string(buf)); err != nil {
			return
		}

		if logger.Level >= dns.LOG_EVENTS {
			logger.Log("loaded %q", fname)
			if logger.Level >= dns.LOG_DEBUG {
				logger.Log("\n%s", x.cfg)
			}
		}
		x.changed = true
		return
	})

	return x, nil
}
// NewCfg returns a newly created Cfg with hosts.File initialized from file fname or an Error of any.
// It binds the contained hosts.File to fname and on any changes to the fname file the Cfg hosts.File
// is reloaded on access via Cfg.File().
NewCfg returns a newly created Cfg with hosts.File initialized from file fname or an Error of any.
It binds the contained hosts.File to fname and on any changes to the fname file the Cfg hosts.File
is reloaded on access via Cfg.File().
// NewCfg returns a newly created Cfg with hosts . File initialized from file fname or an Error of any . // It binds the contained hosts . File to fname and on any changes to the fname file the Cfg hosts . File // is reloaded on access via Cfg . File () .
func NewCfg(fname string, logger *dns.Logger) (c *Cfg, err error) {
	x := &Cfg{cfg: &File{}, logger: logger}
	if x.mfile, err = fileutil.NewGoMFile(fname, os.O_RDONLY, 0444, 0); err != nil {
		return
	}
	if err = x.cfg.Load(fname); err != nil {
		return
	}
	x.mfile.SetHandler(func(file *os.File) (err error) {
		if _, err = file.Seek(0, 0); err != nil {
			return
		}
		buf := []byte{}
		if buf, err = ioutil.ReadAll(file); err != nil {
			return
		}
		if err = x.cfg.LoadString(fname, string(buf)); err != nil {
			return
		}
		if logger.Level >= dns.LOG_EVENTS {
			logger.Log("loaded %q", fname)
			if logger.Level >= dns.LOG_DEBUG {
				logger.Log("\n%s", x.cfg)
			}
		}
		x.changed = true
		return
	})
	return x, nil
}
func NewCfg ( fname string , logger * dns . Logger ) ( c * Cfg , err error ) { x := & Cfg { cfg : & File { } , logger : logger } if x . mfile , err = fileutil . NewGoMFile ( fname , os . O_RDONLY , 0444 , 0 ) ; err != nil { return } if err = x . cfg . Load ( fname ) ; err != nil { return } x . mfile . SetHandler ( func ( file * os . File ) ( err error ) { if _ , err = file . Seek ( 0 , 0 ) ; err != nil { return } buf := [ ] byte { } if buf , err = ioutil . ReadAll ( file ) ; err != nil { return } if err = x . cfg . LoadString ( fname , string ( buf ) ) ; err != nil { return } if logger . Level >= dns . LOG_EVENTS { logger . Log ( " " , fname ) if logger . Level >= dns . LOG_DEBUG { logger . Log ( " \n " , x . cfg ) } } x . changed = true return } ) return x , nil }
NewCfg returns a newly created Cfg with hosts.File initialized from file fname or an Error of any.
NewCfg returns a newly created Cfg with hosts . File initialized from file fname or an Error of any .