Exemplo n.º 1
0
// SetConfig validates,  sets given configuration and resolv listen and daemon
// addresses using new configuration variables.
func (proxy *GitProxy) SetConfig(config zhash.Hash) error {
	listenAddrString, err := config.GetString("git", "listen")
	if err != nil {
		return err
	}

	daemonAddrString, err := config.GetString("git", "daemon")
	if err != nil {
		return err
	}

	storageDir, err := config.GetString("storage")
	if err != nil {
		return err
	}

	listenAddr, err := net.ResolveTCPAddr("tcp", listenAddrString)
	if err != nil {
		return err
	}

	daemonAddr, err := net.ResolveTCPAddr("tcp", daemonAddrString)
	if err != nil {
		return err
	}

	proxy.storageDir = storageDir
	proxy.listenAddr = listenAddr
	proxy.daemonAddr = daemonAddr

	return nil
}
Exemplo n.º 2
0
// SetConfig from zhash.Hash instance which actually is representation of
// map[string]interface{}
// SetConfig validates specified configuration before using.
func (server *Server) SetConfig(config zhash.Hash) error {
	isMaster, err := config.GetBool("master")
	if err != nil && !zhash.IsNotFound(err) {
		return err
	}

	if isMaster {
		slaves, err := config.GetStringSlice("slaves")
		if err != nil && !zhash.IsNotFound(err) {
			return err
		}

		if len(slaves) == 0 {
			logger.Warning("slave servers is not specified")
		} else {
			_, err = config.GetInt("timeout")
			if err != nil {
				return err
			}
		}
	}

	_, err = config.GetString("storage")
	if err != nil {
		return err
	}

	_, err = config.GetString("http", "listen")
	if err != nil {
		return err
	}

	server.config = config

	return nil
}