agent/api/task/taskvolume.go
func (tv *TaskVolume) UnmarshalJSON(b []byte) error {
	// Format: {name: volumeName, host: HostVolume, dockerVolumeConfiguration {}}
	intermediate := make(map[string]json.RawMessage)
	if err := json.Unmarshal(b, &intermediate); err != nil {
		return err
	}
	name, ok := intermediate["name"]
	if !ok {
		return errors.New("invalid Volume; must include a name")
	}
	if err := json.Unmarshal(name, &tv.Name); err != nil {
		return err
	}

	volumeType, ok := intermediate["type"]
	if !ok {
		volumeType = []byte(`"host"`)
		seelog.Infof("Unmarshal task volume: volume type not specified, default to host")
	}
	if err := json.Unmarshal(volumeType, &tv.Type); err != nil {
		return err
	}

	switch tv.Type {
	case HostVolumeType:
		return tv.unmarshalHostVolume(intermediate["host"])
	case DockerVolumeType:
		return tv.unmarshalDockerVolume(intermediate["dockerVolumeConfiguration"])
	default:
		return errors.Errorf("invalid Volume: type must be docker or host, got %q", tv.Type)
	}
}
func (tv *TaskVolume) UnmarshalJSON(b []byte) error {
	// Format: {name: volumeName, host: HostVolume, dockerVolumeConfiguration {}}
	intermediate := make(map[string]json.RawMessage)
	if err := json.Unmarshal(b, &intermediate); err != nil {
		return err
	}
	name, ok := intermediate["name"]
	if !ok {
		return errors.New("invalid Volume; must include a name")
	}
	if err := json.Unmarshal(name, &tv.Name); err != nil {
		return err
	}

	volumeType, ok := intermediate["type"]
	if !ok {
		volumeType = []byte(`"host"`)
		seelog.Infof("Unmarshal task volume: volume type not specified, default to host")
	}
	if err := json.Unmarshal(volumeType, &tv.Type); err != nil {
		return err
	}

	switch tv.Type {
	case HostVolumeType:
		return tv.unmarshalHostVolume(intermediate["host"])
	case DockerVolumeType:
		return tv.unmarshalDockerVolume(intermediate["dockerVolumeConfiguration"])
	default:
		return errors.Errorf("invalid Volume: type must be docker or host, got %q", tv.Type)
	}
}
func ( tv * TaskVolume ) UnmarshalJSON ( b [ ] byte ) error { // Format: {name: volumeName, host: HostVolume, dockerVolumeConfiguration {}} intermediate := make ( map [ string ] json . RawMessage ) if err := json . Unmarshal ( b , & intermediate ) ; err != nil { return err } name , ok := intermediate [ " " ] if ! ok { return errors . New ( " " ) } if err := json . Unmarshal ( name , & tv . Name ) ; err != nil { return err } volumeType , ok := intermediate [ " " ] if ! ok { volumeType = [ ] byte ( `"host"` ) seelog . Infof ( " " ) } if err := json . Unmarshal ( volumeType , & tv . Type ) ; err != nil { return err } switch tv . Type { case HostVolumeType : return tv . unmarshalHostVolume ( intermediate [ " " ] ) case DockerVolumeType : return tv . unmarshalDockerVolume ( intermediate [ " " ] ) default : return errors . Errorf ( " " , tv . Type ) } }
// UnmarshalJSON for TaskVolume determines the name and volume type, and
// unmarshals it into the appropriate HostVolume fulfilling interfaces
UnmarshalJSON for TaskVolume determines the name and volume type and unmarshals it into the appropriate HostVolume fulfilling interfaces