func()

in datahub/implement.go [531:576]


func (datahub *DataHub) GetCursor(projectName, topicName, shardId string, ctype CursorType, param ...int64) (*GetCursorResult, error) {
	if !util.CheckProjectName(projectName) {
		return nil, NewInvalidParameterErrorWithMessage(projectNameInvalid)
	}
	if !util.CheckTopicName(topicName) {
		return nil, NewInvalidParameterErrorWithMessage(topicNameInvalid)
	}
	if !util.CheckShardId(shardId) {
		return nil, NewInvalidParameterErrorWithMessage(shardIdInvalid)
	}
	if len(param) > 1 {
		return nil, NewInvalidParameterErrorWithMessage(parameterNumInvalid)
	}

	path := fmt.Sprintf(shardPath, projectName, topicName, shardId)
	reqPara := &RequestParameter{
		Header: map[string]string{httpHeaderContentType: httpJsonContent},
	}
	gcr := &GetCursorRequest{
		Action:     "cursor",
		CursorType: ctype,
	}

	switch ctype {
	case OLDEST, LATEST:
		if len(param) != 0 {
			return nil, NewInvalidParameterErrorWithMessage("Not need extra parameter when CursorType OLDEST or LATEST")
		}
	case SYSTEM_TIME:
		if len(param) != 1 {
			return nil, NewInvalidParameterErrorWithMessage("Timestamp must be set when CursorType is SYSTEM_TIME")
		}
		gcr.SystemTime = param[0]
	case SEQUENCE:
		if len(param) != 1 {
			return nil, NewInvalidParameterErrorWithMessage("Sequence must be set when CursorType is SEQUENCE")
		}
		gcr.Sequence = param[0]
	}

	respBody, commonResp, err := datahub.Client.Post(path, gcr, reqPara)
	if err != nil {
		return nil, err
	}
	return NewGetCursorResult(respBody, commonResp)
}