예제 #1
0
파일: agent.go 프로젝트: yj2317916/yj-agent
func (a Agent) getgetConnectionInfo() (*yagnats.ConnectionInfo, error) {
	connInfo := new(yagnats.ConnectionInfo)
	natsUrl, err := url.Parse(a.cfg.NatsUrl)
	if err != nil {
		return nil, err
	}
	connInfo.Addr = natsUrl.Host
	connInfo.Username = natsUrl.User.Username()
	connInfo.Password, _ = natsUrl.User.Password()
	return connInfo, nil
}
예제 #2
0
func (h *natsHandler) getConnectionInfo() (*yagnats.ConnectionInfo, error) {
	settings := h.settingsService.GetSettings()

	natsURL, err := url.Parse(settings.Mbus)
	if err != nil {
		return nil, bosherr.WrapError(err, "Parsing Nats URL")
	}

	connInfo := new(yagnats.ConnectionInfo)
	connInfo.Addr = natsURL.Host

	user := natsURL.User
	if user != nil {
		password, passwordIsSet := user.Password()
		if !passwordIsSet {
			return nil, errors.New("No password set for connection")
		}
		connInfo.Password = password
		connInfo.Username = user.Username()
	}

	return connInfo, nil
}