ParseAbsolute takes a string path that may be relative and returns an Absolute that is guaranteed to be absolute, or an error.
(path string)
| 15 | // ParseAbsolute takes a string path that may be relative and returns |
| 16 | // an Absolute that is guaranteed to be absolute, or an error. |
| 17 | func ParseAbsolute(path string) (Absolute, error) { |
| 18 | path, err := filepath.Abs(path) |
| 19 | if err != nil { |
| 20 | return Absolute{}, fmt.Errorf("failed to get absolute path: %w", err) |
| 21 | } |
| 22 | |
| 23 | return Absolute{path: path}, nil |
| 24 | } |
| 25 | |
| 26 | // String returns a string representation of the absolute path, or panics |
| 27 | // if the absolute path is empty. This guards against programmer error. |