Skip to content

Commit c212f69

Browse files
author
Miguel Molina
committed
add NewULIDFromText function
1 parent 16459a8 commit c212f69

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

model.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ func NewULID() ULID {
212212
return id
213213
}
214214

215+
// NewULIDFromText creates a new ULID from its string representation. Will
216+
// return an error if the text is not a valid ULID.
217+
func NewULIDFromText(text string) (ULID, error) {
218+
var id ULID
219+
err := id.UnmarshalText([]byte(text))
220+
return id, err
221+
}
222+
215223
// Scan implements the Scanner interface.
216224
func (id *ULID) Scan(src interface{}) error {
217225
switch src := src.(type) {

0 commit comments

Comments
 (0)