Skip to content

Commit

Permalink
[RFC] Remove prefix param when possible (#223)
Browse files Browse the repository at this point in the history
## Summary

This change removes the prefix param from `FromUUID` and
`FromUUIDBytes`. It follows the philosophy that the correct path should
be easy (and the bad path should be less easy).

Previously to convert a UUID you must do:

```golang
// Previously (ugly)
typeid.FromUUID[idType](idType{}.Prefix(), uuid)

// Or potential bug, pass a string
typeid.FromUUID[idType]("typePrefix", uuid)

// After this change
typeid.FromUUID[idType](uuid)
```

Benefits:

* less code in the correct path.
* Much better type checking and less opportunity for miss-use. No way to
pass a bad prefix.

Downside:

* AnyIDs are a bit longer and uglier.
* Extra functions

Open to renaming `AnyPrefixFromUUID` to something better. Maybe
`FromUUIDWithPrefix` ? or `FromPrefixAndUUID` ?

## How was it tested?

* builds, tests
  • Loading branch information
mikeland73 authored Dec 13, 2023
1 parent 3943bc1 commit c3d838a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cli/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func encodeCmd(cmd *cobra.Command, args []string) error {
prefix = args[0]
uuid = args[1]
}
tid, err := typeid.FromUUID[typeid.AnyID](prefix, uuid)
tid, err := typeid.FromUUIDWithPrefix(prefix, uuid)
if err != nil {
return err
}
Expand Down

0 comments on commit c3d838a

Please sign in to comment.