Exemple #1
0
func prepareAttrValues(topic *string, startTime *string, endTime *string) *map[string]*dynamodb.AttributeValue {
	if !midutil.IsNullOrEmpty(topic) && !midutil.IsNullOrEmpty(startTime) && !midutil.IsNullOrEmpty(endTime) {
		return &map[string]*dynamodb.AttributeValue{
			":v_topic": &dynamodb.AttributeValue{ // Required
				S: topic,
			},
			":v_startTime": &dynamodb.AttributeValue{ // Required
				N: startTime,
			},
			":v_endTime": &dynamodb.AttributeValue{ // Required
				N: endTime,
			},
		}
	}

	if !midutil.IsNullOrEmpty(topic) {
		log.Info("startTime is nill*****")
		return &map[string]*dynamodb.AttributeValue{
			":v_topic": &dynamodb.AttributeValue{ // Required
				S: topic,
			},
		}
	}

	return &map[string]*dynamodb.AttributeValue{}
}
Exemple #2
0
func prepareKeyCondition(topic *string, startTime *string, endTime *string) *string {
	if !midutil.IsNullOrEmpty(topic) && !midutil.IsNullOrEmpty(startTime) && !midutil.IsNullOrEmpty(endTime) {
		return aws.String("topic = :v_topic AND #ts BETWEEN :v_startTime AND :v_endTime")
	}

	if !midutil.IsNullOrEmpty(topic) {
		return aws.String("topic = :v_topic")
	}

	return nil
}
Exemple #3
0
// topics
func GetTopics(rw http.ResponseWriter, req *http.Request) {
	token := req.FormValue("token")
	callback := req.FormValue("callback")

	output, err := SvcSns.ListTopics(&sns.ListTopicsInput{NextToken: aws.String(token)})
	if err != nil {
		midutil.LogAWSRequestErr(rw, req, err)
		return
	}

	if !midutil.IsNullOrEmpty(&callback) {
		Render.JSONP(rw, http.StatusOK, callback, output)
	} else {
		Render.JSON(rw, http.StatusOK, output)
	}

}
Exemple #4
0
// by time range: play/{topic}?start=12345&end=67890
func Playback(rw http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	callback := req.FormValue("callback")

	// query db for playback list
	topic := vars["topic"]
	startTime := req.FormValue("start")
	endTime := req.FormValue("end")

	var queryInput *dynamodb.QueryInput
	lastKey := map[string]*dynamodb.AttributeValue{}

	lastKey = nil
	for {
		log.Println("topic:", topic)
		log.Println("startTime:", startTime)
		log.Println("endTime:", endTime)
		queryInput = prepareQuery(&topic, &startTime, &endTime, &lastKey)

		resp, err := SvcDynamo.Query(queryInput)

		if err != nil {
			midutil.LogAWSRequestErr(rw, req, err)
			return
		}

		processResponse(resp)
		lastKey = resp.LastEvaluatedKey

		if lastKey == nil {
			if !midutil.IsNullOrEmpty(&callback) {
				Render.JSONP(rw, http.StatusOK, callback, resp)
			} else {
				Render.JSON(rw, http.StatusOK, resp)
			}
			break
		} else {
			log.Info("***Paging", lastKey)
		}
	}

	log.Println("playback suceeded!")
}
Exemple #5
0
// by time range: notifications/{topic}?start=12345&end=67890
func GetNotifications(rw http.ResponseWriter, req *http.Request) {
	vars := mux.Vars(req)
	callback := req.FormValue("callback")

	// query db for playback list
	topic := vars["topic"]
	startTime := req.FormValue("start")
	endTime := req.FormValue("end")

	var queryInput *dynamodb.QueryInput
	lastKey := map[string]*dynamodb.AttributeValue{}

	lastKey = nil

	queryInput = prepareQuery(&topic, &startTime, &endTime, &lastKey)

	resp, err := SvcDynamo.Query(queryInput)

	if err != nil {
		midutil.LogAWSRequestErr(rw, req, err)
		return
	}

	if lastKey == nil {
		log.Println("lastKey is nil")
	} else {
		log.Println("lastKey is NOT nil")
	}
	//	convertNotification(resp)
	if !midutil.IsNullOrEmpty(&callback) {
		Render.JSONP(rw, http.StatusOK, callback, resp)
	} else {
		Render.JSON(rw, http.StatusOK, resp)
	}

}