Ejemplo n.º 1
0
Archivo: main.go Proyecto: cycps/addie
func dbUpdate(oid addie.Id, e addie.Identify) {
	log.Printf("[dbUpdate] %T '%s'", e, e.Identify())
	var err error = nil

	var old addie.Identify
	var ok bool

	if reflect.TypeOf(e).Name() == "Model" {
		old, ok = userModels[oid.Name]
		if !ok {
			log.Printf("[Update] bad oid %v\n", oid)
			return
		}
	} else {
		old, ok = design.Elements[oid]
		if !ok {
			log.Printf("[Update] bad oid %v\n", oid)
			return
		}
	}

	//todo perform check old.(type) conversion
	switch t := e.(type) {
	case addie.Computer:
		c := e.(addie.Computer)
		_, err = db.UpdateComputer(oid, old.(addie.Computer), c, user)
	case addie.Switch:
		s := e.(addie.Switch)
		_, err = db.UpdateSwitch(oid, old.(addie.Switch), s, user)
	case addie.Router:
		r := e.(addie.Router)
		_, err = db.UpdateRouter(oid, old.(addie.Router), r, user)
	case addie.Link:
		l := e.(addie.Link)
		_, err = db.UpdateLink(oid, l, user)
	case addie.Phyo:
		p := e.(addie.Phyo)
		_, err = db.UpdatePhyo(oid, p, user)
	case addie.Model:
		m := e.(addie.Model)
		err = db.UpdateModel(oid.Name, m, user)
	case addie.Sax:
		s := e.(addie.Sax)
		_, err = db.UpdateSax(oid, old.(addie.Sax), s, user)
	case addie.Plink:
		p := e.(addie.Plink)
		_, err = db.UpdatePlink(oid, p, user)
	default:
		log.Printf("[dbUpdate] unkown or unsupported element type: %T \n", t)
	}

	if err != nil {
		log.Println(err)
	}

}
Ejemplo n.º 2
0
Archivo: main.go Proyecto: cycps/addie
func dbCreate(e addie.Identify) {
	log.Printf("[dbCreate] %T '%s'", e, e.Identify())
	var err error = nil

	switch t := e.(type) {
	case addie.Computer:
		c := e.(addie.Computer)
		err = db.CreateComputer(c, user)
	case addie.Switch:
		s := e.(addie.Switch)
		err = db.CreateSwitch(s, user)
	case addie.Router:
		r := e.(addie.Router)
		err = db.CreateRouter(r, user)
	case addie.Link:
		l := e.(addie.Link)
		err = db.CreateLink(l, user)
	case addie.Phyo:
		p := e.(addie.Phyo)
		_, err = db.CreatePhyo(p, user)
	case addie.Model:
		m := e.(addie.Model)
		err = db.CreateModel(m, user)
	case addie.Sax:
		s := e.(addie.Sax)
		_, err = db.CreateSax(s, user)
	case addie.Plink:
		p := e.(addie.Plink)
		err = db.CreatePlink(p, user)
	default:
		log.Printf("[dbCreate] unkown or unsupported element type: %T \n", t)
	}

	if err != nil {
		log.Println(err)
	}

}