예제 #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
}