示例#1
0
文件: device.go 项目: tjbx/X10Bridge
// 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
}
示例#2
0
文件: device.go 项目: brutella/hklifx
// 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
}