예제 #1
0
// Extract will return a struct of headers returned from a call to Create. To obtain
// a map of headers, call the ExtractHeader method on the CreateResult.
func (cr CreateResult) Extract() (CreateHeader, error) {
	var ch CreateHeader
	if cr.Err != nil {
		return ch, cr.Err
	}

	if err := gophercloud.DecodeHeader(cr.Header, &ch); err != nil {
		return ch, err
	}

	if date, ok := cr.Header["Date"]; ok && len(date) > 0 {
		t, err := time.Parse(time.RFC1123, cr.Header["Date"][0])
		if err != nil {
			return ch, err
		}
		ch.Date = t
	}

	if date, ok := cr.Header["Last-Modified"]; ok && len(date) > 0 {
		t, err := time.Parse(time.RFC1123, cr.Header["Last-Modified"][0])
		if err != nil {
			return ch, err
		}
		ch.LastModified = t
	}

	return ch, nil
}
예제 #2
0
// Extract will return a struct of headers returned from a call to Delete. To obtain
// a map of headers, call the ExtractHeader method on the DeleteResult.
func (dr DeleteResult) Extract() (DeleteHeader, error) {
	var dh DeleteHeader
	if dr.Err != nil {
		return dh, dr.Err
	}

	if err := gophercloud.DecodeHeader(dr.Header, &dh); err != nil {
		return dh, err
	}

	if date, ok := dr.Header["Date"]; ok && len(date) > 0 {
		t, err := time.Parse(time.RFC1123, dr.Header["Date"][0])
		if err != nil {
			return dh, err
		}
		dh.Date = t
	}

	return dh, nil
}
예제 #3
0
// Extract will return a struct of headers returned from a call to Update. To obtain
// a map of headers, call the ExtractHeader method on the UpdateResult.
func (ur UpdateResult) Extract() (UpdateHeader, error) {
	var uh UpdateHeader
	if ur.Err != nil {
		return uh, ur.Err
	}

	if err := gophercloud.DecodeHeader(ur.Header, &uh); err != nil {
		return uh, err
	}

	if date, ok := ur.Header["Date"]; ok && len(date) > 0 {
		t, err := time.Parse(time.RFC1123, ur.Header["Date"][0])
		if err != nil {
			return uh, err
		}
		uh.Date = t
	}

	return uh, nil
}
예제 #4
0
// Extract will return a struct of headers returned from a call to Get. To obtain
// a map of headers, call the ExtractHeader method on the GetResult.
func (gr GetResult) Extract() (GetHeader, error) {
	var gh GetHeader
	if gr.Err != nil {
		return gh, gr.Err
	}

	if err := gophercloud.DecodeHeader(gr.Header, &gh); err != nil {
		return gh, err
	}

	if date, ok := gr.Header["Date"]; ok && len(date) > 0 {
		t, err := time.Parse(time.RFC1123, gr.Header["Date"][0])
		if err != nil {
			return gh, err
		}
		gh.Date = t
	}

	return gh, nil
}
예제 #5
0
// Extract will return a struct of headers returned from a call to Get. To obtain
// a map of headers, call the ExtractHeader method on the GetResult.
func (gr GetResult) Extract() (GetHeader, error) {
	var gh GetHeader
	if gr.Err != nil {
		return gh, gr.Err
	}

	if err := gophercloud.DecodeHeader(gr.Header, &gh); err != nil {
		return gh, err
	}

	if date, ok := gr.Header["Date"]; ok && len(date) > 0 {
		t, err := time.Parse(time.RFC1123, gr.Header["Date"][0])
		if err != nil {
			return gh, err
		}
		gh.Date = t
	}

	if date, ok := gr.Header["Last-Modified"]; ok && len(date) > 0 {
		t, err := time.Parse(time.RFC1123, gr.Header["Last-Modified"][0])
		if err != nil {
			return gh, err
		}
		gh.LastModified = t
	}

	if date, ok := gr.Header["X-Delete-At"]; ok && len(date) > 0 {
		unix, err := strconv.ParseInt(date[0], 10, 64)
		if err != nil {
			return gh, err
		}
		gh.DeleteAt = time.Unix(unix, 0)
	}

	return gh, nil
}
예제 #6
0
// Extract will return a struct of headers returned from a call to Download. To obtain
// a map of headers, call the ExtractHeader method on the DownloadResult.
func (dr DownloadResult) Extract() (DownloadHeader, error) {
	var dh DownloadHeader
	if dr.Err != nil {
		return dh, dr.Err
	}

	if err := gophercloud.DecodeHeader(dr.Header, &dh); err != nil {
		return dh, err
	}

	if date, ok := dr.Header["Date"]; ok && len(date) > 0 {
		t, err := time.Parse(time.RFC1123, date[0])
		if err != nil {
			return dh, err
		}
		dh.Date = t
	}

	if date, ok := dr.Header["Last-Modified"]; ok && len(date) > 0 {
		t, err := time.Parse(time.RFC1123, date[0])
		if err != nil {
			return dh, err
		}
		dh.LastModified = t
	}

	if date, ok := dr.Header["X-Delete-At"]; ok && len(date) > 0 {
		unix, err := strconv.ParseInt(date[0], 10, 64)
		if err != nil {
			return dh, err
		}
		dh.DeleteAt = time.Unix(unix, 0)
	}

	return dh, nil
}