Example #1
0
func GetAllRole() ([]Role, error) {
	c := db.MDB().C(C_NAME_Role)
	rs := []Role{}
	err := c.Find(nil).All(&rs)
	if err != nil {
		log.Printf("GetAllRole Error: %s", err)
		return rs, err
	}
	return rs, nil
}
Example #2
0
func (self *MongoBackendConfStorage) GetAll() ([]BackendConf, error) {
	c := db.MDB().C(C_NAME_BackendConf)
	bcs := []BackendConf{}
	err := c.Find(nil).All(&bcs)
	if err != nil {
		log.Printf("MongoBackendConfStorage GetAll Error: %s", err)
		return bcs, err
	}
	return bcs, nil
}
Example #3
0
func UpdateRole(id string, role *Role) error {
	c := db.MDB().C(C_NAME_Role)
	change := bson.M{"$set": bson.M{
		"Name":        role.Name,
		"Desc":        role.Desc,
		"Allow":       role.Allow,
		"Deny":        role.Deny,
		"UpdatedTime": time.Now()}}
	err := c.UpdateId(id, change)
	return err
}
Example #4
0
func (self *MongoBackendConfStorage) Update(id string, bc BackendConf) error {
	c := db.MDB().C(C_NAME_BackendConf)
	change := bson.M{"$set": bson.M{
		"AuthType":    bc.AuthType,
		"Desc":        bc.Desc,
		"HostName":    bc.HostName,
		"UpStreams":   bc.UpStreams,
		"UpdatedTime": time.Now()}}
	err := c.UpdateId(id, change)
	return err
}
Example #5
0
func GetRoleByID(id string) (*Role, error) {
	c := db.MDB().C(C_NAME_Role)
	var r Role
	err := c.Find(bson.M{"_id": id}).One(&r)
	if err != nil {
		if err != mgo.ErrNotFound {
			log.Printf("Get Role [%s] Error: %s", id, err)
		}
		return &r, err
	}
	return &r, nil
}
Example #6
0
func (self *MongoBackendConfStorage) Get(hostname string) (BackendConf, error) {
	c := db.MDB().C(C_NAME_BackendConf)
	var bc BackendConf
	err := c.Find(bson.M{"HostName": hostname}).One(&bc)
	if err != nil {
		if err != mgo.ErrNotFound {
			log.Printf("MongoBackendConfStorage Get [%s] Error: %s", hostname, err)
		}
		return bc, err
	}
	return bc, nil
}
Example #7
0
func DeleteRole(id string) error {
	c := db.MDB().C(C_NAME_Role)
	err := c.RemoveId(id)
	return err
}
Example #8
0
func InsertRole(role *Role) error {
	c := db.MDB().C(C_NAME_Role)
	role.Id = bson.NewObjectId().Hex()
	err := c.Insert(role)
	return err
}
Example #9
0
func (self *MongoBackendConfStorage) Delete(id string) error {
	c := db.MDB().C(C_NAME_BackendConf)
	err := c.RemoveId(id)
	return err
}
Example #10
0
func (self *MongoBackendConfStorage) Insert(bc BackendConf) error {
	bc.Id = bson.NewObjectId().Hex()
	c := db.MDB().C(C_NAME_BackendConf)
	err := c.Insert(bc)
	return err
}