Ejemplo n.º 1
0
//creates a new request from a dynmap
func NewRequestDynMap(mp *dynmap.DynMap) *Request {
	request := &Request{
		// version : mp.MustFloat32("strest.v", mp.StrestVersion), //TODO
		version:   StrestVersion,
		uri:       mp.MustString("strest.uri", ""),
		method:    mp.MustString("strest.method", "GET"),
		txnId:     mp.MustString("strest.txn.id", ""),
		txnAccept: mp.MustString("strest.txn.accept", "single"),
		params:    mp.MustDynMap("strest.params", dynmap.New()),
	}

	shardMp, ok := mp.GetDynMap("strest.shard")
	if ok {
		request.Shard = &ShardRequest{
			Partition: shardMp.MustInt("partition", -1),
			Key:       shardMp.MustString("key", ""),
			Revision:  shardMp.MustInt64("revision", int64(-1)),
		}
	} else {
		request.Shard = &ShardRequest{
			Partition: request.params.MustInt(PARAM_SHARD_PARTITION, -1),
			Key:       request.params.MustString(PARAM_SHARD_KEY, ""),
			Revision:  request.params.MustInt64(PARAM_SHARD_REVISION, int64(-1)),
		}
	}
	return request
}