2018-08-26 19:15:48 +08:00
|
|
|
//
|
|
|
|
// Copyright (c) 2018
|
|
|
|
// Mainflux
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Copyright (c) 2018
|
|
|
|
// Mainflux
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//
|
|
|
|
|
2018-05-15 23:13:09 +08:00
|
|
|
package things
|
2017-09-23 07:03:27 +08:00
|
|
|
|
2018-05-21 18:51:46 +08:00
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2018-05-16 20:28:41 +08:00
|
|
|
// IdentityProvider specifies an API for generating unique identifiers.
|
2017-09-23 07:03:27 +08:00
|
|
|
type IdentityProvider interface {
|
2018-05-16 20:28:41 +08:00
|
|
|
// ID generates the unique identifier.
|
|
|
|
ID() string
|
2017-09-23 07:03:27 +08:00
|
|
|
}
|
2018-05-21 18:51:46 +08: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
|
|
|
|
}
|