예제 #1
0
파일: gnatsd.go 프로젝트: cautio/gnatsd
func configureClusterOpts(opts *server.Options) error {
	if opts.ClusterListenStr == "" {
		return nil
	}

	clusterUrl, err := url.Parse(opts.ClusterListenStr)
	h, p, err := net.SplitHostPort(clusterUrl.Host)
	if err != nil {
		return err
	}
	opts.ClusterHost = h
	_, err = fmt.Sscan(p, &opts.ClusterPort)
	if err != nil {
		return err
	}

	if clusterUrl.User != nil {
		pass, hasPassword := clusterUrl.User.Password()
		if !hasPassword {
			return fmt.Errorf("Expected cluster password to be set.")
		}
		opts.ClusterPassword = pass

		user := clusterUrl.User.Username()
		opts.ClusterUsername = user
	}

	return nil
}
예제 #2
0
파일: main.go 프로젝트: yingkitw/gnatsd
func configureClusterOpts(opts *server.Options) error {
	if opts.ClusterListenStr == "" {
		if opts.RoutesStr != "" {
			server.PrintAndDie("Solicited routes require cluster capabilities, e.g. --cluster.")
		}
		return nil
	}

	clusterURL, err := url.Parse(opts.ClusterListenStr)
	h, p, err := net.SplitHostPort(clusterURL.Host)
	if err != nil {
		return err
	}
	opts.ClusterHost = h
	_, err = fmt.Sscan(p, &opts.ClusterPort)
	if err != nil {
		return err
	}

	if clusterURL.User != nil {
		pass, hasPassword := clusterURL.User.Password()
		if !hasPassword {
			return fmt.Errorf("Expected cluster password to be set.")
		}
		opts.ClusterPassword = pass

		user := clusterURL.User.Username()
		opts.ClusterUsername = user
	}

	// If we have routes but no config file, fill in here.
	if opts.RoutesStr != "" && opts.Routes == nil {
		opts.Routes = server.RoutesFromStr(opts.RoutesStr)
	}

	return nil
}