Beispiel #1
0
func (ts *Tribserver) CreateUser(args *tribproto.CreateUserArgs, reply *tribproto.CreateUserReply) error {
	// Set responses by modifying the reply structure, like:
	// reply.Status = tribproto.EEXISTS

	//check errors for any calls to libstore

	//call libstore.get on the user
	_, exists := ts.lstore.Get(args.Userid)
	//if error is found, then user does not exist yet
	if exists != nil {
		err1 := ts.lstore.Put(args.Userid, "0")
		if err1 != nil {
			return err1
		}
		//then set reply to OK
		reply.Status = tribproto.OK
		return nil
	}

	//else, the user already exists and we can't create
	//set reply to EEXISTS
	reply.Status = tribproto.EEXISTS
	//return nil
	return nil

}
Beispiel #2
0
/**@brief create a new user
 * @param CreateUserArgs
 * @param CreateUserReply
 * @return error
 */
func (ts *Tribserver) CreateUser(
	args *tribproto.CreateUserArgs, reply *tribproto.CreateUserReply) error {

	var trib_key, fllw_key string
	var err error

	trib_key = fmt.Sprintf("%s:T", args.Userid)
	fllw_key = fmt.Sprintf("%s:F", args.Userid)

	_, err = ts.Store.GetList(trib_key)
	if err == nil {
		lsplog.Vlogf(0, "try create user %s , but exist !", args.Userid)
		reply.Status = tribproto.EEXISTS
		return nil
	}

	err = ts.Store.Put(trib_key, "")
	if lsplog.CheckReport(2, err) {
		lsplog.Vlogf(0, "user %s , trib_key exist !", args.Userid)
		reply.Status = tribproto.EEXISTS
		return nil
	}

	err = ts.Store.Put(fllw_key, "")
	if lsplog.CheckReport(2, err) {
		reply.Status = tribproto.EEXISTS
		return nil
	}

	reply.Status = tribproto.OK

	lsplog.Vlogf(0, "create user status %d", tribproto.OK)

	return nil
}
Beispiel #3
0
func (ts *Tribserver) CreateUser(args *tribproto.CreateUserArgs, reply *tribproto.CreateUserReply) error {
	_, err := ts.ls.Get(args.Userid)
	if err == nil {
		reply.Status = tribproto.EEXISTS
		return nil
	}
	err = ts.ls.Put(args.Userid, args.Userid)
	if err != nil {
		return err
	}
	reply.Status = tribproto.OK
	return nil
}