func makePartFromContainer(name string) (v Parts, err error) {
	// this block pulls out functionality from
	// PrintLineByContainerName{Id} & printLine
	var contID *docker.Container
	cont, exists := util.ParseContainers(name, true)
	if exists {
		contID, err = util.DockerClient.InspectContainer(cont.ID)
		if err != nil {
			return Parts{}, err
		}
	}
	if err != nil {
		return Parts{}, err
	}
	tmp, err := reflections.GetField(contID, "Name")
	if err != nil {
		return Parts{}, err
	}

	n := tmp.(string)

	Names := util.ContainerDisassemble(n)

	v = Parts{
		ShortName: Names.ShortName,
		//Running: set in previous function
		FullName:    Names.FullName,
		PortsOutput: util.FormulatePortsOutput(contID),
	}
	return v, nil
}
Beispiel #2
0
// this function populates the listing functions
func printLine(container *docker.Container) ([]string, error) {
	tmp, err := reflections.GetField(container, "Name")
	if err != nil {
		return nil, err
	}
	n := tmp.(string)

	Names := util.ContainerDisassemble(n)
	parts := []string{Names.ShortName, Names.FullName, Names.Type, fmt.Sprintf("%d", Names.Number), formulatePortsOutput(container)}
	return parts, nil
}
Beispiel #3
0
func ExampleGetField() {
	s := MyStruct{
		FirstField:  "first value",
		SecondField: 2,
		ThirdField:  "third value",
	}

	fieldsToExtract := []string{"FirstField", "ThirdField"}

	for _, fieldName := range fieldsToExtract {
		value, err := reflections.GetField(s, fieldName)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(value)
	}
}
Beispiel #4
0
// this function populates the listing functions only for flags/tests
func printLine(container *docker.Container, existing bool) ([]string, error) {
	tmp, err := reflections.GetField(container, "Name")
	if err != nil {
		return nil, err
	}
	n := tmp.(string)

	var running string
	if !existing {
		running = "Yes"
	} else {
		running = "No"
	}

	Names := ContainerDisassemble(n)

	parts := []string{Names.ShortName, Names.Type, running, Names.FullName, fmt.Sprintf("%d", Names.Number), formulatePortsOutput(container)}
	return parts, nil
}
// this function populates the listing functions only for flags/tests
func printLine(container *docker.Container, existing bool) ([]string, error) {
	tmp, err := reflections.GetField(container, "Name")
	if err != nil {
		return nil, err
	}
	n := tmp.(string)

	var running string
	if !existing {
		running = "Yes"
	} else {
		running = "No"
	}

	Names := ContainerDisassemble(n)

	parts := []string{Names.ShortName, "", running, Names.FullName, FormulatePortsOutput(container)}
	if err := CheckParts(parts); err != nil {
		return []string{}, err
	}
	return parts, nil
}
Beispiel #6
0
func makePartFromContainer(name string, defs bool) (v Parts, err error) {
	if defs {
		v.ShortName = name // the only value needed for known
	} else {
		// this block pulls out functionality from
		// PrintLineByContainerName{Id} & printLine
		var contID *docker.Container
		cont, exists := ParseContainers(name, true)
		if exists {
			contID, err = DockerClient.InspectContainer(cont.ID)
			if err != nil {
				return Parts{}, err
			}
		}
		if err != nil {
			return Parts{}, err
		}
		tmp, err := reflections.GetField(contID, "Name")
		if err != nil {
			return Parts{}, err
		}

		n := tmp.(string)

		Names := ContainerDisassemble(n)

		v = Parts{
			ShortName: Names.ShortName,
			Type:      Names.Type,
			//Running: set in previous function
			FullName:    Names.FullName,
			Number:      Names.Number,
			PortsOutput: formulatePortsOutput(contID),
		}
	}
	return v, nil
}