format runs a format function based on the value of the provided attribute.
()
| 49 | |
| 50 | // format runs a format function based on the value of the provided attribute. |
| 51 | func (p *FormatParams) format() (val interface{}, err error) { |
| 52 | switch p.Attribute { |
| 53 | case "name": |
| 54 | val = formatName(p.Args[0], p.Value.(string)) |
| 55 | case "size": |
| 56 | val, err = p.formatSize() |
| 57 | case "time": |
| 58 | val, err = p.formatTime() |
| 59 | } |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | if val == nil { |
| 64 | return nil, &ErrUnsupportedFormat{p.Args[0], p.Attribute} |
| 65 | } |
| 66 | return val, nil |
| 67 | } |
| 68 | |
| 69 | // formatSize formats a size. Valid arguments include `KB`, `MB`, `GB` (case |
| 70 | // insensitive). |
no test coverage detected