func parseNetworkMetadata(settings *types.NetworkSettings, hostConfig *dockercontainer.HostConfig) (NetworkMetadata, error) {
	// Network settings and Host configuration should not be missing except due to errors
	if settings == nil {
		err := fmt.Errorf("parse network metadata: could not find network settings")
		return NetworkMetadata{}, err
	}

	if hostConfig == nil {
		err := fmt.Errorf("parse network metadata: could not find host configuration")
		return NetworkMetadata{}, err
	}

	// This metadata is the information provided in older versions of the API
	// We get the NetworkMode (Network interface name) from the HostConfig because this
	// this is the network with which the container is created
	ipv4AddressFromSettings := settings.IPAddress
	networkModeFromHostConfig := string(hostConfig.NetworkMode)

	// Extensive Network information is not available for Docker API versions 1.17-1.20
	// Instead we only get the details of the first network
	networkList := make([]Network, 0)
	if len(settings.Networks) > 0 {
		for modeFromSettings, containerNetwork := range settings.Networks {
			networkMode := modeFromSettings
			ipv4Addresses := []string{containerNetwork.IPAddress}
			network := Network{NetworkMode: networkMode, IPv4Addresses: ipv4Addresses}
			networkList = append(networkList, network)
		}
	} else {
		ipv4Addresses := []string{ipv4AddressFromSettings}
		network := Network{NetworkMode: networkModeFromHostConfig, IPv4Addresses: ipv4Addresses}
		networkList = append(networkList, network)
	}

	return NetworkMetadata{
		networks: networkList,
	}, nil
}
func parseNetworkMetadata(settings *types.NetworkSettings, hostConfig *dockercontainer.HostConfig) (NetworkMetadata, error) {
	// Network settings and Host configuration should not be missing except due to errors
	if settings == nil {
		err := fmt.Errorf("parse network metadata: could not find network settings")
		return NetworkMetadata{}, err
	}

	if hostConfig == nil {
		err := fmt.Errorf("parse network metadata: could not find host configuration")
		return NetworkMetadata{}, err
	}

	// This metadata is the information provided in older versions of the API
	// We get the NetworkMode (Network interface name) from the HostConfig because this
	// this is the network with which the container is created
	ipv4AddressFromSettings := settings.IPAddress
	networkModeFromHostConfig := string(hostConfig.NetworkMode)

	// Extensive Network information is not available for Docker API versions 1.17-1.20
	// Instead we only get the details of the first network
	networkList := make([]Network, 0)
	if len(settings.Networks) > 0 {
		for modeFromSettings, containerNetwork := range settings.Networks {
			networkMode := modeFromSettings
			ipv4Addresses := []string{containerNetwork.IPAddress}
			network := Network{NetworkMode: networkMode, IPv4Addresses: ipv4Addresses}
			networkList = append(networkList, network)
		}
	} else {
		ipv4Addresses := []string{ipv4AddressFromSettings}
		network := Network{NetworkMode: networkModeFromHostConfig, IPv4Addresses: ipv4Addresses}
		networkList = append(networkList, network)
	}

	return NetworkMetadata{
		networks: networkList,
	}, nil
}
// parseNetworkMetadata parses the docker.NetworkSettings struct and
// packages the desired metadata for JSON marshaling
// Since we accept incomplete metadata fields, we should not return
// errors here and handle them at this stage.