Exemplo n.º 1
0
func ParseServiceType(params []string) ([]string, string, *mpqerr.ErrorResponse) {
	valName := params[0]
	if len(params) >= 2 {
		svcType := params[1]
		if svcType != "pqueue" && svcType != "pq" {
			return nil, "", mpqerr.InvalidRequest("Unknown service type: " + svcType)
		}
		return params[2:], svcType, nil
	}
	return nil, "", mpqerr.InvalidRequest(valName + " must be followed by service type")
}
Exemplo n.º 2
0
func ParseStringParam(params []string, minLen, maxLen int64) ([]string, string, *mpqerr.ErrorResponse) {
	valName := params[0]
	if len(params) < 2 {
		return nil, "", mpqerr.InvalidRequest(makeStrDesc(valName, minLen, maxLen))
	}
	paramLen := int64(len(params[1]))
	if paramLen >= minLen && paramLen <= maxLen {
		return params[2:], params[1], nil
	}
	return nil, "", mpqerr.InvalidRequest(makeStrDesc(valName, minLen, maxLen))
}
Exemplo n.º 3
0
func ParseInt64Param(params []string, minValue, maxValue int64) ([]string, int64, *mpqerr.ErrorResponse) {
	valName := params[0]
	if len(params) < 2 {
		return nil, 0, mpqerr.InvalidRequest(makeIntDesc(valName, minValue, maxValue))
	}
	val, err := strconv.ParseInt(params[1], 10, 0)

	if err == nil && val >= minValue && val <= maxValue {
		return params[2:], val, nil
	}

	return nil, 0, mpqerr.InvalidRequest(makeIntDesc(valName, minValue, maxValue))
}
Exemplo n.º 4
0
// Call dispatches to the command handler to process necessary parameters.
func (ctx *PQContext) Call(cmd string, params []string) apis.IResponse {
	if ctx.finishFlag {
		return mpqerr.ERR_CONN_CLOSING
	}
	ctx.callsCount += 1
	switch cmd {
	case PQ_CMD_POPLOCK:
		return ctx.PopLock(params)
	case PQ_CMD_POP:
		return ctx.Pop(params)
	case PQ_CMD_MSG_INFO:
		return ctx.GetMessageInfo(params)
	case PQ_CMD_DELETE_BY_RCPT:
		return ctx.DeleteByReceipt(params)
	case PQ_CMD_UNLOCK_BY_RCPT:
		return ctx.UnlockByReceipt(params)
	case PQ_CMD_DELETE_LOCKED_BY_ID:
		return ctx.DeleteLockedById(params)
	case PQ_CMD_DELETE_BY_ID:
		return ctx.DeleteById(params)
	case PQ_CMD_PUSH:
		return ctx.Push(params)
	case PQ_CMD_UPD_LOCK_BY_ID:
		return ctx.UpdateLockById(params)
	case PQ_CMD_UPD_LOCK_BY_RCPT:
		return ctx.UpdateLockByRcpt(params)
	case PQ_CMD_UNLOCK_BY_ID:
		return ctx.UnlockMessageById(params)
	case PQ_CMD_STATUS:
		return ctx.GetCurrentStatus(params)
	case PQ_CMD_SET_CFG:
		return ctx.SetParamValue(params)
	case PQ_CMD_CHECK_TIMEOUTS:
		return ctx.CheckTimeouts(params)
	case PQ_CMD_PURGE:
		ctx.pq.Clear()
		return resp.OK_RESPONSE
	}
	return mpqerr.InvalidRequest("Unknown command: " + cmd)
}