func NewBuilder()

in client/channel/channel.go [88:141]


func NewBuilder(connection string) (*ChannelBuilder, error) {

	u, err := url.Parse(connection)
	if err != nil {
		return nil, err
	}

	if u.Scheme != "sc" {
		return nil, errors.New("URL schema must be set to `sc`.")
	}

	var port = 15002
	var host = u.Host
	// Check if the host part of the URL contains a port and extract.
	if strings.Contains(u.Host, ":") {
		hostStr, portStr, err := net.SplitHostPort(u.Host)
		if err != nil {
			return nil, err
		}
		host = hostStr
		if len(portStr) != 0 {
			port, err = strconv.Atoi(portStr)
			if err != nil {
				return nil, err
			}
		}
	}

	// Validate that the URL path is empty or follows the right format.
	if u.Path != "" && !strings.HasPrefix(u.Path, "/;") {
		return nil, fmt.Errorf("The URL path (%v) must be empty or have a proper parameter syntax.", u.Path)
	}

	cb := &ChannelBuilder{
		Host:    host,
		Port:    port,
		Headers: map[string]string{},
	}

	elements := strings.Split(u.Path, ";")
	for _, e := range elements {
		props := strings.Split(e, "=")
		if len(props) == 2 {
			if props[0] == "token" {
				cb.Token = props[1]
			} else if props[0] == "user_id" {
				cb.User = props[1]
			} else {
				cb.Headers[props[0]] = props[1]
			}
		}
	}
	return cb, nil
}