示例#1
0
文件: flags.go 项目: kshi0310/geard
func (p *PortPairs) Set(s string) error {
	ports, err := port.FromPortPairHeader(s)
	if err != nil {
		fmt.Fprintln(os.Stderr, err.Error())
		return err
	}
	p.PortPairs = &ports
	return nil
}
示例#2
0
文件: marshal.go 项目: kshi0310/geard
func (h *HttpInstallContainerRequest) UnmarshalHttpResponse(headers http.Header, r io.Reader, mode client.ResponseContentMode) (interface{}, error) {
	if r == nil {
		pending := make(map[string]interface{})
		if s := headers.Get("X-" + cjobs.PendingPortMappingName); s != "" {
			ports, err := port.FromPortPairHeader(s)
			if err != nil {
				return nil, err
			}
			pending[cjobs.PendingPortMappingName] = ports
		}
		return pending, nil
	}
	return nil, errors.New("Unexpected response body to HttpInstallContainerRequest")
}
示例#3
0
文件: ports.go 项目: roacobb/geard
func readPortsFromUnitFile(r io.Reader) (port.PortPairs, error) {
	pairs := make(port.PortPairs, 0, 4)
	scan := bufio.NewScanner(r)
	for scan.Scan() {
		line := scan.Text()
		if strings.HasPrefix(line, "X-PortMapping=") {
			ports := strings.TrimPrefix(line, "X-PortMapping=")
			found, err := port.FromPortPairHeader(ports)
			if err != nil {
				continue
			}
			pairs = append(pairs, found...)
		}
	}
	if scan.Err() != nil {
		return pairs, scan.Err()
	}
	return pairs, nil
}