// NewDevice returns a client for a specific name either loaded from the database // or newly created. func NewDevice(name string, database db.Database) (Device, error) { var err error entity := database.EntityWithName(name) if entity == nil { entity, err = db.NewRandomEntityWithName(name) if err == nil { err = database.SaveEntity(entity) } } return &device{entity}, err }
// NewDevice returns a client for a specific name either loaded from the database // or newly created. func NewDevice(name string, database db.Database) (Device, error) { var e db.Entity var err error if e, err = database.EntityWithName(name); err != nil { if e, err = db.NewRandomEntityWithName(name); err == nil { err = database.SaveEntity(e) } } return &device{e}, err }