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 }
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 }
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 }
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 }
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 }
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 }
func DeleteRole(id string) error { c := db.MDB().C(C_NAME_Role) err := c.RemoveId(id) return err }
func InsertRole(role *Role) error { c := db.MDB().C(C_NAME_Role) role.Id = bson.NewObjectId().Hex() err := c.Insert(role) return err }
func (self *MongoBackendConfStorage) Delete(id string) error { c := db.MDB().C(C_NAME_BackendConf) err := c.RemoveId(id) return err }
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 }