Refactor Register Funktion
This commit is contained in:
parent
c79d1f86e4
commit
7db9c374cc
5 changed files with 129 additions and 21 deletions
|
@ -1,7 +1,8 @@
|
|||
package device
|
||||
|
||||
type Device struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Keys map[string]*Key `json:"keys,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
AccessToken string `json:"accessToken,omitempty"`
|
||||
Keys map[string]*Key `json:"keys,omitempty"`
|
||||
}
|
||||
|
|
|
@ -1,5 +1,30 @@
|
|||
package device
|
||||
|
||||
func New() (device *Device) {
|
||||
import "nutfactory.org/Matrix/utils"
|
||||
|
||||
func New(name string) (err error, device *Device) {
|
||||
err, id := utils.CreateUUID()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err, token := utils.CreateToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
device = &Device{
|
||||
Id: id,
|
||||
Name: name,
|
||||
AccessToken: token,
|
||||
Keys: make(map[string]*Key),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (device *Device) RenewAccesToken() (err error) {
|
||||
err, token := utils.CreateToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
device.AccessToken = token
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue