func unsafeSave(cfg *config, configPath string) {
	buf, errYaml := yaml.Marshal(cfg)
	if errYaml != nil {
		log.Printf("configSave: marshal: %s: %v", configPath, errYaml)
		return
	}
	if err := ioutil.WriteFile(configPath, buf, 0640); err != nil {
		log.Printf("configSave: %s: %v", configPath, err)
	}
	log.Printf("configSave: %s", configPath)
}
get a lock before calling unsafeSave
will read from shared config
will write into shared file
package main
import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"sync"
	"gopkg.in/yaml.v2"
	"github.com/udhos/disbalance/rule"
)
func ruleUpdate(name string, old, update rule.Rule) rule.Rule {
	r := rule.Rule{
		Protocol: old.Protocol,
		Listener: old.Listener,
		Targets:  map[string]rule.Target{},
	}
	for a, t := range old.Targets {
		r.Targets[a] = t
	}
	if update.Protocol != "" {
		r.Protocol = update.Protocol
	}
	if update.Listener != "" {
		r.Listener = update.Listener
	}
	for a, t := range update.Targets {
		r.Targets[a] = t
	}
	return r
}
type config struct {
	BasicAuthUser string
	BasicAuthPass string
	Rules         map[string]rule.Rule
}
type server struct {
	cfg        config
	configPath string
	apis       []string
	lock       sync.RWMutex
	fwd        map[string]forwarder
}
func (s *server) enableForwarders() {
	s.lock.Lock()
	defer s.lock.Unlock()
	for ruleName := range s.cfg.Rules {
		s.forwardEnable(ruleName)
	}
}