當前位置: 首頁>>代碼示例>>Golang>>正文


Golang urlutil.IsTransportURL函數代碼示例

本文整理匯總了Golang中github.com/docker/docker/pkg/urlutil.IsTransportURL函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsTransportURL函數的具體用法?Golang IsTransportURL怎麽用?Golang IsTransportURL使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了IsTransportURL函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: parseAddress

func parseAddress(address string) (string, string, error) {
	if address == "" {
		return "", "", nil
	}
	if !urlutil.IsTransportURL(address) {
		return "", "", fmt.Errorf("syslog-address should be in form proto://address, got %v", address)
	}
	url, err := url.Parse(address)
	if err != nil {
		return "", "", err
	}

	// unix and unixgram socket validation
	if url.Scheme == "unix" || url.Scheme == "unixgram" {
		if _, err := os.Stat(url.Path); err != nil {
			return "", "", err
		}
		return url.Scheme, url.Path, nil
	}

	// here we process tcp|udp
	host := url.Host
	if _, _, err := net.SplitHostPort(host); err != nil {
		if !strings.Contains(err.Error(), "missing port in address") {
			return "", "", err
		}
		host = host + ":514"
	}

	return url.Scheme, host, nil
}
開發者ID:beerbubble,項目名稱:docker,代碼行數:31,代碼來源:syslog.go

示例2: parseAddress

func parseAddress(address string) (string, string, error) {
	if urlutil.IsTransportURL(address) {
		url, err := url.Parse(address)
		if err != nil {
			return "", "", err
		}

		// unix socket validation
		if url.Scheme == "unix" {
			if _, err := os.Stat(url.Path); err != nil {
				return "", "", err
			}
			return url.Scheme, url.Path, nil
		}

		// here we process tcp|udp
		host := url.Host
		if _, _, err := net.SplitHostPort(host); err != nil {
			if !strings.Contains(err.Error(), "missing port in address") {
				return "", "", err
			}
			host = host + ":514"
		}

		return url.Scheme, host, nil
	}

	return "", "", nil
}
開發者ID:vito,項目名稱:garden-linux-release,代碼行數:29,代碼來源:syslog.go

示例3: parseAddress

func parseAddress(address string) (*location, error) {
	if address == "" {
		return &location{
			protocol: defaultProtocol,
			host:     defaultHost,
			port:     defaultPort,
			path:     "",
		}, nil
	}

	protocol := defaultProtocol
	givenAddress := address
	if urlutil.IsTransportURL(address) {
		url, err := url.Parse(address)
		if err != nil {
			return nil, errors.Wrapf(err, "invalid fluentd-address %s", givenAddress)
		}
		// unix and unixgram socket
		if url.Scheme == "unix" || url.Scheme == "unixgram" {
			return &location{
				protocol: url.Scheme,
				host:     "",
				port:     0,
				path:     url.Path,
			}, nil
		}
		// tcp|udp
		protocol = url.Scheme
		address = url.Host
	}

	host, port, err := net.SplitHostPort(address)
	if err != nil {
		if !strings.Contains(err.Error(), "missing port in address") {
			return nil, errors.Wrapf(err, "invalid fluentd-address %s", givenAddress)
		}
		return &location{
			protocol: protocol,
			host:     host,
			port:     defaultPort,
			path:     "",
		}, nil
	}

	portnum, err := strconv.Atoi(port)
	if err != nil {
		return nil, errors.Wrapf(err, "invalid fluentd-address %s", givenAddress)
	}
	return &location{
		protocol: protocol,
		host:     host,
		port:     portnum,
		path:     "",
	}, nil
}
開發者ID:haoshuwei,項目名稱:docker,代碼行數:55,代碼來源:fluentd.go

示例4: parseAddress

func parseAddress(address string) (string, error) {
	if urlutil.IsTransportURL(address) {
		url, err := url.Parse(address)
		if err != nil {
			return "", err
		}

		// we support only udp
		if url.Scheme != "udp" {
			return "", fmt.Errorf("gelf: endpoint needs to be UDP")
		}

		// get host and port
		if _, _, err = net.SplitHostPort(url.Host); err != nil {
			return "", fmt.Errorf("gelf: please provide gelf-address as udp://host:port")
		}

		return url.Host, nil
	}

	return "", nil
}
開發者ID:vito,項目名稱:garden-linux-release,代碼行數:22,代碼來源:gelf.go


注:本文中的github.com/docker/docker/pkg/urlutil.IsTransportURL函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。