Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
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")
}
Exemplo n.º 3
0
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
}