NewName creates a new [Name] from a string If a validation error occurs, it returns nil and the error.
(s string)
| 36 | // NewName creates a new [Name] from a string |
| 37 | // If a validation error occurs, it returns nil and the error. |
| 38 | func NewName(s string) (Name, error) { |
| 39 | if err := validName(s); err != nil { |
| 40 | return nil, fmt.Errorf("parsing name: %w", err) |
| 41 | } |
| 42 | return &name{ |
| 43 | value: s, |
| 44 | }, nil |
| 45 | } |
| 46 | |
| 47 | // MustNewName creates a new Name as [NewName] does, but panics when a validation |
| 48 | // error occurs. |