func (r *router) RegisterHandler(address string, redirect Redirect) error {
	if _, ok := r.redirectHandlers[address]; ok {
		return fmt.Errorf("cannot register multiple redirects for address %s", address)
	}

	// add handler
	r.redirectLock.Lock()
	r.redirectHandlers[address] = redirect.ToHandler()
	r.redirectLock.Unlock()

	// configure watcher for upgrading handler on file changes
	go func() {
		w, err := redirect.RestartWatcher()
		if err != nil {
			logrus.Errorf("unable to set up watcher for redirect %s", redirect)
		}
		defer w.Close()
		for {
			select {
			case event, ok := <-w.Events:
				if !ok {
					return
				}
				if event.Op&fsnotify.Write == fsnotify.Write {
					r.redirectLock.Lock()
					r.redirectHandlers[address] = redirect.ToHandler()
					r.redirectLock.Unlock()
				}
			case err, ok := <-w.Errors:
				if !ok {
					return
				}
				logrus.Error(err)
			}
		}
	}()
	return nil
}
// RegisterHandler configures a redirect to the provided address
RegisterHandler configures a redirect to the provided address
// RegisterHandler configures a redirect to the provided address
func (r *router) RegisterHandler(address string, redirect Redirect) error {
	if _, ok := r.redirectHandlers[address]; ok {
		return fmt.Errorf("cannot register multiple redirects for address %s", address)
	}
	r.redirectLock.Lock()
	r.redirectHandlers[address] = redirect.ToHandler()
	r.redirectLock.Unlock()
	go func() {
		w, err := redirect.RestartWatcher()
		if err != nil {
			logrus.Errorf("unable to set up watcher for redirect %s", redirect)
		}
		defer w.Close()
		for {
			select {
			case event, ok := <-w.Events:
				if !ok {
					return
				}
				if event.Op&fsnotify.Write == fsnotify.Write {
					r.redirectLock.Lock()
					r.redirectHandlers[address] = redirect.ToHandler()
					r.redirectLock.Unlock()
				}
			case err, ok := <-w.Errors:
				if !ok {
					return
				}
				logrus.Error(err)
			}
		}
	}()
	return nil
}
func ( r * router ) RegisterHandler ( address string , redirect Redirect ) error { if _ , ok := r . redirectHandlers [ address ] ; ok { return fmt . Errorf ( " " , address ) } r . redirectLock . Lock ( ) r . redirectHandlers [ address ] = redirect . ToHandler ( ) r . redirectLock . Unlock ( ) go func ( ) { w , err := redirect . RestartWatcher ( ) if err != nil { logrus . Errorf ( " " , redirect ) } defer w . Close ( ) for { select { case event , ok := <- w . Events : if ! ok { return } if event . Op & fsnotify . Write == fsnotify . Write { r . redirectLock . Lock ( ) r . redirectHandlers [ address ] = redirect . ToHandler ( ) r . redirectLock . Unlock ( ) } case err , ok := <- w . Errors : if ! ok { return } logrus . Error ( err ) } } } ( ) return nil }
RegisterHandler configures a redirect to the provided address
RegisterHandler configures a redirect to the provided address
// add handler // configure watcher for upgrading handler on file changes