2018-05-15 17:13:09 +02:00
|
|
|
package things
|
2017-09-23 01:03:27 +02:00
|
|
|
|
2018-05-21 12:51:46 +02:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2018-05-16 14:28:41 +02:00
|
|
|
// IdentityProvider specifies an API for generating unique identifiers.
|
2017-09-23 01:03:27 +02:00
|
|
|
type IdentityProvider interface {
|
2018-05-16 14:28:41 +02:00
|
|
|
// ID generates the unique identifier.
|
|
|
|
ID() string
|
2017-09-23 01:03:27 +02:00
|
|
|
}
|
2018-05-21 12:51:46 +02:00
|
|
|
|
|
|
|
// FromString extracts an unsigned integer from given string value. Since
|
|
|
|
// unsigned integers are used for thing and channel identifiers, malformed
|
|
|
|
// extraction will result in ErrNotFound error.
|
|
|
|
func FromString(v string) (uint64, error) {
|
|
|
|
base := 10
|
|
|
|
bitSize := 64
|
|
|
|
|
|
|
|
id, err := strconv.ParseUint(v, base, bitSize)
|
|
|
|
if err != nil {
|
|
|
|
return 0, ErrNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
return id, nil
|
|
|
|
}
|